SoFunction
Updated on 2025-04-09

Python pip replacement image source problem and solution

Python pip replacement image source problem

Commonly used mirror sources:

  • Tsinghua University:/simple
  • Alibaba Cloud:/pypi/simple/
  • University of Science and Technology of China:/simple/

1. Temporarily use the mirror source

If you only need to use the mirror source occasionally, you can use it when installing the package-iParameter Specifies.

For example:

pip install <package_name> -i /simple

Here-iThe parameter is followed by the URL of the mirror source.

For example:

Install numpy:

# Tsinghua Mirrorpip install numpy -i /simple
# Alibaba Cloud Mirrorpip install numpy -i /pypi/simple/

2. Permanently configure the mirror source

To avoid manually specifying the image source every time the package is installed, the image source can be set permanently through the configuration file.

For example:

# Permanently configure Alibaba Cloud image sourcepip config set -url /simple

Verify that the configuration is effective:

Run the following command to view the current configuration:

pip config list

3. Attachment: Mirroring configuration for Conda

If you useconda, editable~/.condarc(Linux/macOS) orC:\Users\<username>\.condarc(Windows), add the following content (taking Tsinghua mirror as an example):

channels:
  - defaults
show_channel_urls: true
default_channels:
  - /anaconda/pkgs/main
  - /anaconda/pkgs/r
  - /anaconda/pkgs/msys2
custom_channels:
  conda-forge: /anaconda/cloud
  pytorch: /anaconda/cloud

Summarize

  • Temporary use: Add it directly in the command-i <mirror source address>
  • Permanently effective:Revisepiporcondaconfiguration file.
  • It is recommended to use domestic mirror sources such as Tsinghua University or Alibaba Cloud, which are faster.

The above is personal experience. I hope you can give you a reference and I hope you can support me more.