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
usepip
When commanded, pass-i
Parameters 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_name
Bag. You can also use other mirror sources, such as:
- Douban:/simple/
- Tsinghua University:/simple
Permanently configure the mirror source
You can modifypip
configuration file to allow all subsequentpip
All 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
pip
Concurrent download dependencies have been supported since version 20.3, you can use it--use-feature=fast-deps
Parameters 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 usepipreqs
Tools 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 useconda
Commands to manage dependencies.
conda
Have your own mirror source and in some cases download faster.
Configure conda image source
You can use the following command to configure Tsinghua Universityconda
Mirror source:
conda config --add channels /anaconda/pkgs/free/ conda config --add channels /anaconda/pkgs/main/ conda config --set show_channel_urls yes
Installation dependencies
useconda
The 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.