Due to some unavoidable factors, the official Python packages are sometimes inaccessible or have network instability in China. conda source also has the problem of network link failure. To solve this problem, here are some configuration methods to sort out.

Pip vs. Conda

Dependency checking

  • pip: does not always show the required additional dependencies. When installing a package, it may simply ignore the dependencies and install them, only indicating errors in the results.
  • conda: Lists additional required dependencies. The dependencies are automatically installed when the package is installed. You can easily switch between different versions of a package.

Environment management

  • pip: It is difficult to maintain multiple environments.
  • conda: It is easier to switch between environments, and environment management is simpler.

Impact on the system’s own Python

  • pip: Updating/rewinding versions/uninstalling packages in system-installed Python will affect other programs.
  • conda: It will not affect the system’s own Python.

Applicable languages

  • pip: Only applies to Python.
  • conda: works with Python, R, Ruby, Lua, Scala, Java, JavaScript, C/C++, FORTRAN.

Python pip source modifications

Common pip sources.

Temporary use : Add the -i parameter to specify the pip source when using pip

1
pip install scrapy -i https://pypi.tuna.tsinghua.edu.cn/simple

Permanent modification :.

  • Windows: create pip directory under user folder and create in file (%HOMEPATH%\pip\pip.ini) under pip directory
  • Linux/MAC OS: path and file name in: ~/.pip/pip.conf (if you want it to take effect globally, the file can be placed in /etc/pip.conf)

Write the following in the file (index-url can be replaced by the pip source you want to use)

1
2
3
4
[global]
trusted-host=mirrors.aliyun.com
index-url=https://mirrors.aliyun.com/pypi/simple/
Anaconda conda源的修改

According to the Anaconda software source, Anaconda and Miniconda are trademarks of Anaconda, Inc. and any unauthorized public mirroring is not permitted. For its part, Anaconda, Inc. has agreed to open mirroring privileges to educational and research institutions on the condition that traffic information is provided.

The following is a compilation of available conda sources.

modify configuration file

  1. Generate the accompanying configuration file by the command: conda config -set show_channel_urls yes

  2. Modify the generated directory configuration file .condarc

  • Windows is "%HOMEPATH%\.condarc"
  • Linux/MAC OS is"~/.condarc"

Recommended configuration content.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
ssl_verify: False
channels:
  - defaults
default_channels:
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
show_channel_urls: true

If there are still problems with the network, add a proxy at

1
2
3
proxy_servers:
    http: http://127.0.0.1:55959
    https: http://127.0.0.1:55959
  1. Run conda clean -i to clear the index cache and ensure that the index provided by the mirror site is used.

Command Line Direct Configuration

Enter the following command directly from the command line.

1
2
3
4
5
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --set show_channel_urls yes

If a Conda HTTP Error is returned, you need to remove the third-party mirror link and revert to the default settings:.

1
2
3
conda config --remove-key channels
conda config --show # 查看conda的配置,确认channels
conda config --show-sources # 仅查看所有镜像

Add channels for r, conda-forge, bioconda.

1
2
3
conda config --add channels r # R软件包
conda config --add channels conda-forge # Conda社区维护的不在默认通道中的软件
conda config --add channels bioconda # 生物信息学类工具