Python trick operation: eight ways to install modules

1. Use easy_install

easy_install This should be the oldest package installation method, and no one uses it anymore. Here are some installation examples of easy_install

# Find the latest version from PyPI through the package name, automatically download, compile, and install  
$ easy_install pkg_name   Many people learn python and don’t know where to start. 
Many people learn python and after mastering the basic grammar, they don't know where to find cases to get started. 
Many people who have done case studies do not know how to learn more advanced knowledge. 
For these three types of people, I will provide you with a good learning platform, free to receive video tutorials, e-books, and course source code! ??¤ QQ群:232030553 
# Find the link from the specified download page to install or upgrade the package by the package name  
$ easy_install -f http://pythonpaste.org/package_index.html   
# Specify the online package address to install  
$ easy_install http:/ /example.com/path/to/MyPackage-1.2.3.tgz  
# Install from the local .egg file  
$ easy_install xxx.egg 


 
 

2. Use pip install

Pip is the most mainstream package management solution. Use pip install xxx to search and install xxx from PYPI (if the package exists).

Only some common installation examples of pip install are listed below

$ pip install requests  
 
# You must ensure that you have downloaded the pkg package to the /local/wheels directory  
$ pip install --no-index --find-links=/local/wheels pkg  
 
# The version of the installed package is 2.1. 2  
$ pip install pkg==2.1.2  
 
# The installed package must be greater than or equal to 2.1.2  
$ pip install pkg>=2.1.2  
 
# The installed package must be less than or equal to 2.1.2  
$ pip install pkg<=2.1.2 

For more pip usage methods, please refer to the article I wrote before, the introduction is very clear: the most comprehensive pip usage guide, 50% you may not have used it.

3. Use pipx

Pipx is a tool specially used to install and manage cli applications. The Python packages installed with it will be installed separately into a brand new unique virtual environment.

Since it is a third-party tool, you need to install it before using it

$ python3 -m pip install --user pipx 
$ python3 -m userpath append ~/.local/bin 
Success! 

After installation, you can use pipx to install the cli tool.

# Create a virtual environment and install the package  
$ pipx install pkg 

For more ways to use pipx, please refer to the article I wrote before. The introduction is very clear: unlock the new posture of the bag. In this scenario, pip is really difficult to use~

4. Use setup.py

If you have written a setup.py file, you can use the following command to install directly

# Use source code to install directly  
$ python setup.py install 

5. Use yum

When a Python package is built using setup.py, there are multiple options for the package release format, one of which is bdist_rpm, and the package released with this option is in the rpm package format.

# Publish rpm package  
$ python setup.py bdist_rpm 

For the rpm format, you need to use yum install xxx or rpm install xxx to install.

# Use yum to install  
$ yum install pkg  
 
# Use rpm to install  
$ rpm -ivh pkg 

6. Use pipenv

If you are in a virtual environment created with pipenv, you can use the following command to install the package into the virtual environment

$ pipenv install pkg 

7. Use poetry

If you use poetry to manage project dependencies, you can use the following command to install the package

# Install the package directly  
$ poetry add pkg  
 
# Specify as a development dependency  
$ poetry add pytest --dev 

8. Use curl + pipeline

There are some installation methods provided by third-party toolkits, which directly use the curl configuration pipeline to install

$ curl -sSL <url> | python 

For example, the poetry mentioned above can be installed in this way.

$ curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python 

The above are the eight methods of installing packages I have summarized. Although they are not considered to be dazzling techniques, but after summarizing, I found that there are so many methods that have some fits with the articles in this series, so I simply put them under this dazzling technique series.

Guess you like

Origin blog.csdn.net/Python_sn/article/details/111553013