SoFunction
Updated on 2025-04-11

How to quickly download dependencies in Python

Python fast download dependencies

In Python, to quickly download dependencies, you can use the following methods:

1. Use domestic mirror source

Python dependencies are usually downloaded from the Python Package Index (PyPI), but due to network problems, downloading from foreign sources may be slower.

You can use domestic mirror sources to speed up download speed. Common domestic mirror sources include Alibaba Cloud, Douban, Tsinghua University, etc.

Temporary use of mirror sources

usepipWhen commanded, pass-iParameters specify the mirror source, the example is as follows:

pip install package_name -i /pypi/simple/

The above command is downloaded using Alibaba Cloud Image Sourcepackage_nameBag. You can also use other mirror sources, such as:

  • Douban/simple/
  • Tsinghua University/simple

Permanently configure the mirror source

You can modifypipconfiguration file to allow all subsequentpipAll operations use the specified mirror source.

On Windows,%APPDATA%\pip\Directory (usually C:\Users\your username\AppData\Roaming\pip) CreateThe file content is as follows:

[global]
index-url = /pypi/simple/

On Linux or macOS,~/.pip/Directory creationThe file, the content is also:

[global]
index-url = /pypi/simple/

2. Use pip's concurrent download function

pipConcurrent download dependencies have been supported since version 20.3, you can use it--use-feature=fast-depsParameters enable this function, the example is as follows:

pip install package_name --use-feature=fast-deps

This feature will download multiple dependency packages in parallel, thereby speeding up downloading.

3. Use pipreqs to download project dependencies in batches

To download the dependencies of the entire project, you can usepipreqsTools automatically generate project dependency files, download all dependencies once again.

Install pipreqs

pip install pipreqs

Generate file

Execute the following command in the project root directory:

pipreqs .

This command will automatically scan the project file and generateFile containing all the dependencies and their versions required by the project.

Batch download dependencies

Run the following command in the project root directory and download it at one timeAll dependencies in:

pip install -r 

4. Use conda to manage dependencies (for Anaconda or Miniconda users)

If you use Anaconda or Miniconda environment, you can usecondaCommands to manage dependencies.

condaHave your own mirror source and in some cases download faster.

Configure conda image source

You can use the following command to configure Tsinghua UniversitycondaMirror source:

conda config --add channels /anaconda/pkgs/free/
conda config --add channels /anaconda/pkgs/main/
conda config --set show_channel_urls yes

Installation dependencies

usecondaThe commands for installing dependencies are as follows:

conda install package_name

Through the above methods, you can significantly increase the download speed of Python dependencies.

Summarize

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