Elegant use of Python software management, python Management
In the previous article, "elegant environment management with python" (the rich python software package is also one of its advantages, so you do not need to repeat the wheel ). This article describes how to manage Python software packages elegantly.
Common Software Package management tools
Generally, python software package management tools mainly include:
Figure common python package management tools
We can see that distribute is an alternative to setuptools (because the Setuptools package is no longer maintained), and pip is an alternative to easy_install. This article focuses on pip and others interested in it.
Pip's most popular software package management tool
Donald Stufft, one of pip's core developers, wrote a blog last year describing the 4-day traffic of the PyPI CDN supplier. One latitude is displayed. about 75% of the users who use the software package management tool to install the software package from PyPI use pip. This tool has proved to be very useful and popular,In2013Year 10Monthly pipWill be removed from 3.4Starting with pythonBuilt-in release.
Figure: PyPI Installation tool usage Statistical Chart (https://caremad.io/2013/10/a-look-at-pypi-downloads)
Install the recommended software package on the PyPI homepage:
Install
Method 1:
L download get-pip.py files, https://bootstrap.pypa.io/get-pip.py
L python get-pip.py
D: \ Python33> python get-pip.py
Downloading/unpacking pip
Downloading/unpacking setuptools
Installing collected packages: pip, setuptools
Successfully installed pip setuptools
Cleaning up...
Method 2: source code Installation
L download source package: https://pypi.python.org/packages/source/p/pip/
L decompress
L cd to the corresponding directory
L python setup. py install
Use
L install the software package from PyPI:
$ pip install SomePackage
[...]
Successfully installed SomePackage
L view the files and paths installed in the software package:
$ pip show --files SomePackage
Name: SomePackage
Version: 1.0
Location: /my/env/lib/pythonx.x/site-packages
Files:
../somepackage/__init__.py
[...]
L check which software packages have updated:
$ pip list --outdated
SomePackage (Current: 1.0 Latest: 2.0)
L upgrade software package:
$ pip install --upgrade SomePackage
[...]
Found existing installation: SomePackage 1.0
Uninstalling SomePackage:
Successfully uninstalled SomePackage
Running setup.py install for SomePackage
Successfully installed SomePackage
L uninstall the software package:
$ pip uninstall SomePackage
Uninstalling SomePackage:
/my/env/lib/pythonx.x/site-packages/somepackage
Proceed (y/n)? y
Successfully uninstalled SomePackage
Pip advanced usage
The previous section describes the basic functions of pip, which have already met most of the requirements. The following describes some advanced usage of pip:
L query software packages
$ pip search "query"
L list all installed software packages
$ pip list
L specified version number of the installation package
Use =, >=, <=, >,< to specify a version number.
$ pip install SomePackage # latest version
$ pip install SomePackage==1.0.4 # specific version
$ pip install 'SomePackage>=1.0.4' # minimum version
L install software packages based on dependent files
Imagine a scenario where "elegant environment management using python" is used to create a virtual environment that feels like it, install some dependent software packages, and develop an application APP. In this case, do you need to deploy it on the server?
In this case, you can use pip to export the dependency file list, and then automatically install the corresponding software package on the server based on the dependency file list. Is it convenient!
Pip freeze> requirements.txt
Pip install-r requirements.txt
Related connections:
Https://pip.pypa.io/en/latest/installing.html
Https://pip.pypa.io/en/latest/quickstart.html