Pip is a tool we often use. After all, Python is a famous programming language with a large third-party library, so we always use pip to install some dependent libraries. Of course, this is only the most commonly used command of PIP. Here are some commands you need to master in PIP.
I personally use anaconda, so I need to operate in Anaconda prompt. If you use the python version downloaded from the official website, you can operate directly in CMD.
pip
Directly enter pip to view all command parameters and options:
View the location of PIP:
where pip
Update PIP version:
pip install --upgrade pip
If your PIP version is relatively low, there will be yellow warnings like the following when using pip. Personally, it is recommended not to update it if it can be used. It is easy to report errors after updating.
install
Here, for example, the flash library is temporarily used to install the flash library. The latest version is installed by default:
pip install flask
Specify the version of the flash library to install:
PIP install flash = = version number
When installing third-party libraries, we may be very slow, or even read timed out. There are two solutions. The first is to use the timeout parameter to increase the time:
pip install flask --timeout 6000
The second is to use some domestic images. The format is as follows:
PIP install flash - I image source
Here are some stable and fast domestic images. The most commonly used image is Tsinghua image:
Tsinghua University: https://pypi.tuna.tsinghua.edu.cn/simple
Alibaba cloud: http://mirrors.aliyun.com/pypi/simple/
China University of science and technology https://pypi.mirrors.ustc.edu.cn/simple/
Huazhong University of Technology: http://pypi.hustunique.com/
Shandong University of Technology: http://pypi.sdutlinux.org/
Watercress: http://pypi.douban.com/simple/
PIP also supports the installation of packages in specified files. When will it be used? For example, we have created a new virtual environment without any libraries, but it is very troublesome for us to install libraries one by one. We can import the packages in the global environment into files, and then install them in the virtual environment at one time. You only need to install some libraries needed in the virtual environment.
This kind of operation is recommended to be used at the pychar terminal because it involves the generation of files. You can directly find files in the directory. The specific operations are as follows:
pip freeze > requirements.txt
This command will generate a text file containing all the libraries installed in your environment and their corresponding versions:
Then enter the virtual environment and enter the following command, PIP will install all the libraries in the file:
pip install -r requirements.txt
see
pip list
pip freeze
You can see that both commands can get the installed library and the corresponding version information. The visible difference between the two is that the format is different, and the latter can export files. In addition, there are some detailed differences that will not be introduced here.
pip show flask
Query some basic information of a library, mainly including version number, home page, location and some dependencies of the Library:
This instruction is used to query more specific information of a library:
pip show -f flask
to update
pip list --outdated
When querying which libraries need to be updated, the current version and the latest version of the library will be returned:
Another form:
pip list -o
To upgrade a library, you can also specify the desired version number:
pip install --upgrade flask
Another form:
pip install -U flask
uninstall
When uninstalling a third-party library, it should be noted that some libraries in PIP are self-contained and do not support uninstallation.
pip uninstall flask
Like the installation principle, PIP uninstallation also supports uninstalling multiple libraries at one time through files.
Uninstall PIP itself:
python -m pip uninstall pip
Pay attention to the official account [milk candy] to get more wonderful articles.