Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Python package management tool pip

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article editor for you a detailed introduction of the "Python package management tool pip how to use", the content is detailed, the steps are clear, the details are handled properly, I hope this "Python package management tool pip how to use" article can help you solve doubts, the following follow the editor's ideas slowly in depth, together to learn new knowledge.

Get to know pip

As we all know, pip can install, update and uninstall the third-party library of python, which is very convenient.

The full name of pip: package installer for python, which is the Python package management tool.

Some people may have been using pip for a long time, but it is not clear what the package management tool is.

Let's start with the language Python. Python is popular not only because it is easy to learn, but also because it has thousands of treasures.

These libraries are equivalent to integrated tools that can be used in Python as long as they are installed. They can handle all kinds of problems without you having to reinvent the wheel, and as the community updates and maintains, some libraries become more and more powerful, almost comparable to enterprise applications.

So how to download and install these tool libraries? They are placed in a unified "warehouse" called PyPi (Python Package Index), where all library installations are scheduled.

Once you have a warehouse, you need an administrator, and pip is such a role. Pip takes libraries out of PyPi, installs them into Python, and manages installed libraries, such as update, view, search, uninstall, and so on.

Generally speaking, the butler of pip's Python third-party library, understanding it, will save you a lot of trouble.

"Note: because pip is a command line program, pip generally performs various operations on the command line."

1. Install pip

Since Python 3.4, pip has been built into Python, so there is no need to install it again.

If your version of Python does not have pip, you can install it in the following two ways.

(1) enter easy_install pip on the command line, which is very fast.

(2) download the pip installation file from the following URL, then extract it to the python scripts directory, and execute the python setup.py install installation.

2. View the pip version

Pip-version

3. Upgrade pip

If the version of pip is too low, you can upgrade the current version

Pip install-upgrade pip

4. Get help

To learn how to use pip and what pip does, execute the following statement for a detailed tutorial:

Pip help

5. Install the library

To install a third-party library using pip, execute the following statement

Pip install package_name

Specify the package version:

Pip install package_name==1.1.2

For example, I want to install version 3.4.1 of matplotlib

Pip install matplotlib==3.4.1

6. Batch installation library

If a project requires a lot of libraries to be installed, you can install it in bulk:

Pip install-re:\ requirements.txt

7. Install the library using wheel files

This method is suitable for offline installation. The wheel file is the source file of the library and can be downloaded and installed locally.

The steps are as follows:

(1) find the .whl file of the corresponding library in the following website

(2) download the .whl file and pay attention to the corresponding version

(3) in the folder where .whl is located, press shift + right mouse button to open the CMD window or PowerShell

(4) enter the command:

Pip install matplotlib-3.4.1-cp39-cp39-win_amd64.whl

Installation can be completed.

8. Unloading library

Installed libraries can be uninstalled again:

Pip uninstall package_name

9. Upgrade library

Upgrade the version of the current library:

Pip install-upgrade package_name

10. Check the library information

Pip show-f package_name

11. View installed libraries

List all installed third-party libraries and corresponding versions

Pip list

12. Save the list of libraries to the specified file

Save the installed library information to a local txt file:

Pip freeze > requirements.txt

13. View the libraries that need to be upgraded

Among the libraries that have been installed, see which ones need to be upgraded.

Pip list-o

14. Check compatibility issues

Verify that installed libraries have compatibility dependency issues

Pip check package-name

15. Download the library to local

Download the library to a local specified file and save it in whl format

Pip download package_name-d "File path to save"

Attached: replace the pip source

Many people complain that the pip installation library is sometimes too slow, and that's the problem with the pip source.

As mentioned earlier, pip downloads library files from PyPi, but because the PyPi server is abroad, access is slow.

However, many mirror sources are provided in China to replace PyPi, such as Tsinghua Yuan, Douban Yuan, Ali Yunyuan and so on.

These mirror sources back up the data in PyPi, because the server is in China, the speed will be much faster.

However, the mirror source data has a lag. For example, the pypi image of Tsinghua Source is synchronized every 5 minutes.

There are two ways to use mirror sources. Take Tsinghua Source as an example:

(1) temporary use

Pip install-I https://pypi.tuna.tsinghua.edu.cn/simple some-package matplotlib

Except that matplotlib is the library name to be installed, everything else is in a fixed format.

(2) set as default

Pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

When set as the default, the future installation libraries will be downloaded from Tsinghua source, and there is no need to add mirror source URL

Read this, the "Python package management tool pip how to use" article has been introduced, want to master the knowledge of this article also need to practice and use to understand, if you want to know more about the article, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report