Python's Package management tool

Source: Internet
Author: User

There are already many mature packages in the Python environment that can be installed to extend our programs.

For example, many times Python developers go to the PyPI site to find the package they want to use, and then install it. PyPI (Python package Index) is a site that obtains third-party python packages to complement the standard library.

In the process of installing a Python package, it often involves distutils, setuptools, distribute, setup.py, Easy_install, Easy_install, and Pip, among others.

Suddenly the package management of Python is messy, what are these tool relationships and how should I choose to use them?

The following is a brief introduction to the Python package management related to some of the content.

Python Package management tool

With so many Python package management tools, there's a little bit of a choice when it comes to Python. In fact, after checking the official documents of Python, the relationship between these tools is slowly cleared up, and there is no such confusion.

The following is a brief introduction to the package management tools in Python, respectively.

Distutils

Distutils is part of the Python standard library, which is designed to provide developers with a convenient way to package, while providing users with a convenient way to install.

The setup.py we often use is based on distutils, and can be packaged or installed through setup.py.

Looking at a simple example, find a directory to create three files foo.py, bar.py, and setup.py, where the contents of setup.py are as follows:

 fromDistutils.coreImportSetupsetup (Name='FooBar', Version='1.0', author=' would', Author_email='[email protected]', the URL='http://www.cnblogs.com/wilber2013/', Py_modules=['Foo','Bar'],)

Then, running python setup.py sdist in that directory, you get the following output, and a "Foobar-1.0.zip" package is generated.

The user can unzip the package and execute the python setup.py Install, then use the two modules Foo and bar:

For more information on how to write setup.py, refer to the Setupscript section of the official Python documentation for yourself.

Setuptools and distribute

Setuptools is an enhancement to distutils, especially the introduction of package dependency Management. We can install Setuptools through ez_setup.py.

As for distribute, it is a branch version of Setuptools. The reason for branching is that some developers think Setuptools development is too slow. But now, distribute is merged back into the Setuptools, so you can think of them as the same thing.

Before you see setup.py can create a compressed package, and Setuptools uses a new file format (. Egg), you can create an egg file for the Python package. Setuptools can identify the. egg file and parse it, install it

Easy_install

Once the Setuptools/distribute is installed, we can use the Easy_install tool directly:

    1. install a package from PyPI : When using the easy_install Package command, Easy_install can automatically download the relevant packages from PyPI and complete the installation, upgrade
    2. Download a package installation : The easy_install package.tgz command allows you to install a package that has already been downloaded
    3. Install the Egg file : You can install a file in egg format via easy_install Package.egg

You can get help tips for this command with the easy_install--help command:

Based on the above analysis, you can see the relationship between Setuptools/distribute and Easy_install:

    • Setuptools/distribute has expanded the distutils, providing more functionality
    • Easy_install is a setuptools/distribute-based tool that facilitates the installation of packages and the provincial
Pip

Pip is currently the most popular Python package management tool and is used as a substitute for easy_install, but there is still a lot of functionality built on Setuptools.

Easy_install has a lot of disadvantages: The installation transaction is non-atomic, it only supports SVN, does not provide the Unload command, and you need to write a script to install a series of packages. Pip solves the above problems and has become a new fact standard.

Pip is very simple to use and supports installing a Python package from any address that can be accessed through a VCS or browser:

    • Installation: pip install somepackage
    • Uninstall: pip uninstall Somepackage

The following section of the article focuses on PIP-related content.

Using PIP

In Python, it is recommended to use PIP for Python package management, PIP installation and use is more convenient.

PIP installation

There are two common ways to install PIP:

    1. Download the get-pip.py file and execute the python get-pip.py for installation (if Setuptools is not installed, then get-pip.py will help install it)
    2. Now PIP source package, and then install through setup.py
Pip Common Commands

For Pip, the most commonly used is the pip--help , and with the help of the document, you can probably know how to use commands and parameters.

Pip Common Command collection:

Use

Command

Installing packages from PyPI

Pip Install Somepackage

Uninstalling packages

Pip Uninstall Somepackage

View to install the package

PIP List

View Upgradeable Packages

Pip List--outdated

Upgrade Packages

Pip Install--upgrade somepackage

View information about which files and paths are installed on the package

Pip Show--files Somepackage

Install the specified version number of the package

Pip Install Somepackage

# Latest Version

Pip Install somepackage==1.0.4

# Specific Version

Pip install ' somepackage>=1.0.4 '

# Minimum version

Install packages based on dependent files

Pip Freeze > Requirements.txt

# Export a list of dependent files using PIP

Pip Install-r requirements.txt

# automatically installs the corresponding package according to the list of dependent files

Summarize

This article describes the relationship between the various package management tools of Python, and I believe that through the introduction of this article, we will no longer distutils, setuptools, distribute, setup.py, Easy_install, Easy_ The nouns like install and pip are confusing.

After a general understanding of these Python package management tools, you should also know how to choose and use.

This article does not deal with how to create and publish a Python package, interested students can go to the Python official online search.

Python's Package management tool

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.