Detailed Explanation of Eight Methods of Packaging in Python Development
- 2021-12-11 08:04:35
- OfStack
1. Use easy_install
easy_install
This should be the oldest package installation method, which is basically not used at present. Below is
easy_install
Some 1 Installation Examples of
# By package name, from PyPI Find the latest version, download, compile and install automatically
$ easy_install pkg_name
# Find a link from the specified download page by package name to install or upgrade the package
$ easy_install -f http://pythonpaste.org/package_index.html
# Specify the package address installation on the line
$ easy_install http://example.com/path/to/MyPackage-1.2.3.tgz
# From local .egg File installation
$ easy_install xxx.egg
2. Use pip install
pip is the most popular package management solution, using
pip install xxx
You can search and install it from PYPI
xxx
(If the package exists).
Here are just one of the most commonly used
pip install
Installation example of
$ pip install requests
# The premise is that you have to make sure that you have downloaded it pkg Package to /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 information on how to use pip, please refer to my previous article, which is very clear: 8.8 Detailed Guide to the Use of pip
3. Use pipx
pipx is a tool dedicated to installing and managing cli applications, and the Python packages installed with it will be installed separately into a new unique virtual environment.
Because 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!
Installation is ready to use pipx to install the cli tool.
# Create a virtual environment and install packages
$ pipx install pkg
For more information on how to use pipx, please refer to my previous article, which is very clear: 12.4 Guide to the Use of pipx Installer
4. Use setup. py
If you have written setup. py files, you can install them directly using the following command
# Install directly using source code
$ python setup.py install
5. Use yum
The Python package is in use
setup.py
When building, there are many options for the publishing format of the package, among which one option is
bdist_rpm
The package published with this option is
rpm
Gets or sets the package format of.
# Publish rpm Bag
$ python setup.py bdist_rpm
For
rpm
This format, you need to use
yum install xxx
Or
easy_install
0
To install.
# Use yum Installation
$ yum install pkg
# Use rpm Installation
$ rpm -ivh pkg
6. Use pipenv
If you are in a virtual environment created using pipenv, you can use the following command to install the package into the virtual environment
$ pipenv install pkg
7. Use poetry
If you have project dependencies managed using poetry, you can install the package using the following command
# Direct installation package
$ poetry add pkg
# Specify as development dependency
$ poetry add pytest --dev
8. Use the curl + pipe
Some third-party kits provide installation methods that use the curl configuration pipe directly, such as the above-mentioned poetry can be installed in this way.
$ curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python
That's what I shared today. Is it a gesture?
If the content is helpful to you, can you please give me a compliment? hhhh
More articles in this series
Python Programming Skills 8 Operating Methods of Connection List
Three Applications of Walrus Operator in Python Development Skills
Five Python escape notations
The above is the Python development package 8 methods of detailed explanation of the details, more about Python package 8 methods of information please pay attention to other related articles on this site!