With the wide application of Python in data science, machine learning and other fields, the number of Python packages is also increasing. pip is a Python package manager that can easily download, install and update various packages. Due to domestic network environment restrictions, accessing the official pip source is slow. At this time, it is necessary to optimize the pip mirror source configuration and speed up the update and installation of Python packages.
The following are specific steps and code examples:
Enter the following command in the terminal to check the pip version:
pip --version
If pip has been installed, the following information will be displayed:
pip X.X from /path/to/pip (python X.X)
In the ~/.pip/pip.conf file Add the following configuration information:
[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple/ # 清华大学的镜像站
Or the mirror site of Alibaba Cloud:
[global] index-url = https://mirrors.aliyun.com/pypi/simple/
Enter the following command in the terminal to create the configuration file:
mkdir ~/.pip touch ~/.pip/pip.conf
Enter the following command to verify the new Check whether the mirror station is working properly:
pip config list
This will list the current pip configuration information to ensure that the new mirror station has been set up successfully.
For some reasons, you may need to upgrade the setuptools and wheel packages before updating pip. Enter the following command in the terminal:
pip install --upgrade setuptools pip install --upgrade wheel
Then you can update pip:
pip install --upgrade pip
Use the optimized pip mirror source , which can speed up the installation of Python packages. Just enter the following command in the terminal:
pip install package_name
Among them, package_name is the name of the Python package that needs to be installed. If the package that needs to be installed depends on other packages, pip will automatically download and install the dependent packages.
Enter the following command in the terminal to list the installed Python packages in the current environment:
pip list
If you need to uninstall an installed Python package, you can enter the following command in the terminal:
pip uninstall package_name
Among them, package_name is the name of the Python package that needs to be uninstalled. .
Summary
By configuring the pip mirror source, you can speed up the update and installation of Python packages. Both Tsinghua University and Alibaba Cloud provide complete pip mirror station services. Users can choose the appropriate mirror source according to their own network environment. When using pip, you can also specify which mirror source to use through command line parameters.
The above is the detailed content of Improve pip mirror source settings and improve Python package update and installation speed. For more information, please follow other related articles on the PHP Chinese website!