Pip common commands, learning Python will not be difficult (26)

Hello children, hello big friends!

I'm Cat Girl, a primary school student who fell in love with Python programming.

Welcome to learn Python with cat girl.

today's topic

Learn how to use pip.

pip

what is pip

The full name of pip is Python Package Index, a software library for the Python programming language.

Similar to Centos' yum, Ubuntu's apt, and Java's Maven.

We all know that Python has many third-party libraries (modules), how to import these libraries into your own project?

Python's official pypi warehouse (pypi.org) provides us with a unified code hosting warehouse.

Python package management tool

Python has two package management tools easy_install and pip.

Python2, easy_install is installed by default, and pip needs to be installed manually.

With the upgrade of Python version, easy_install is gradually eliminated, and only a few older and more partial libraries still need to be installed through easy_install.

pip is currently the mainstream package installation tool, and pip is used by default after Python2>2.79 or Python>=3.4.

What if pip is not installed

What if pip is not checked during the installation of Python?

It is checked by default. If you cancel it manually, you can install pip later.

Pip is very commonly used. It is recommended to install pip according to the default configuration.

  1. Manually go to bootstrap.pypa.io to find and download the corresponding version of get-pip.py file

  2. python get-pip.py

If you are under Linux, you can do this:

  1. Download and install the version curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

  2. Run the install script sudo python get-pip.py

Commonly used pip commands

Check the pip version:

pip -V

pip --version

pip command help:

pip --help

Package installation:

pip install sign up

Such as pip install requests

The simulation is to install the latest version

Specify package version installation:

pip install package name==version

pip install package name>=version

Package update:

pip install -U package name

Package uninstallation:

pip uninstall package name

For example pip uninstall requests

Search package (retrieved on server):

pip search package keywords

Display package information:

pip show package name

View details of a specified package:

pip show -f packagename

List installed libraries:

pip list

Save the list of installed libraries to a text file:

pip freeze>c:\requirement.txt

Install libraries in batches according to dependency files:

pip install -r c:\requirement.txt

Install using the wheel file:

pip install ******.whl

pip upgrade:

pip install -U pip

pip install --upgrade pip

python -m pip install -i https://pypi.douban.com/simple  --upgrade pip

The system will prompt

Domestic mirror source

By default, pip uses pypi.org. Because the server is not in China, the access will often time out. At this time, you can use domestic mirror sources, such as Tsinghua University, Douban, etc.

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

pip install -i https://pypi.douban.com/simple some-package

If you want to configure the domestic mirror source as the default address, you can refer to the following configuration:

  1. Create a new pip folder under c:\users\xxx\AppData\Roaming

  2. Create a new pip.ini in the pip directory, the content is as follows:

[global]

index-url=http://pypi.douban.com/simple

trusted-host=pypi.douban.com

Reasons for failure of pip installation library

If the installation fails, it is necessary to analyze the specific problem and see what error message the error prompts.

  1. Open cmd as an administrator and use pip. Haven't encountered it yet.

  2. Use domestic mirror sources. An error message will prompt a timeout.

  3. The library has been installed, but the version is relatively old, you can upgrade it, or uninstall it and install it again.

Where is the library installed by pip installed ?

Lib\site-packages in the Python installation directory

Generally, there are 2 folders, taking django as an example:

django: the main program, usually the main program that runs when it is running

Django-4.1.1.dist-info: additional information

The difference between pip and pip3

probably like this

1. Pip is a package management tool for python. The versions of pip and pip3 are different, and they are both located in the Scripts\ directory:

2. If only Python2 is installed in the system, then only pip can be used.

3. If only Python3 is installed in the system, you can use either pip or pip3, the two are equivalent.

4. If both Python2 and Python3 are installed in the system, pip is used for Python2 by default, and pip3 is assigned for Python3.

5. Important: In the virtual environment, if there is only one python version, it can be considered that the pip and pip3 commands in the system are the same

Well, let's learn this today!

If you encounter any problems, let's communicate and solve them together.

I'm Cat Girl, see you next time!

Guess you like

Origin blog.csdn.net/parasoft/article/details/130036221