Python Package (module)

Source: Internet
Author: User
Python package management differences in different ways

have been learning python for some time, often encounter the problem of installing various packages, a setup.py, a will easy_install, one will be pip, there are some concepts such as distutils, Setuptools and so on, do not know who is who, When you should use something, clarify these concepts today.

Distutils

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

For example, you create a package called Foo that contains a foo.py file that you want to package for others to use. At this point you need to write a setup.py file:

From Distutils.core Import Setup

Setup (name= ' foo ',

Version= ' 1.0 ',

py_modules=[' foo '),

)

Then run the command

$python setup.py sdist

Then you find a folder named Dist in the current directory with a foo-1.0.tar.gz package. There are three files in this package, foo.py, setup.py, Pkg-info, and the first two files are the same as the two files we mentioned earlier. Pkg-info is some information about the package. Then you can install the foo-1.0.tar.gz to someone else.

When the installer wants to use this package, it only needs to unzip the foo-1.0.tar.gz file and run the command

$python Setup Install

This package will be automatically installed to the appropriate location of the system.

Setuptools

Setuptools is an enhancement to distutils, especially the introduction of package dependency Management.

Setuptools can create an egg file for a Python package, and the relationship between Python and the egg file is equivalent to the relationship between Java and the jar package.

The Easy_install script provided by Setuptools can be used to install the egg package. In addition, Easy_install can automatically download the relevant packages from the PyPI and complete the installation and upgrade.

Easy_install provides a variety of ways to install and upgrade Python packages, such as:

Easy_install Sqlobject

Easy_install-f http://pythonpaste.org/package_index.html Sqlobject

Easy_install http://example.com/path/to/MyPackage-1.2.3.tgz

Easy_install/my_downloads/otherpackage-3.2.1-py2.3.egg

Easy_install--upgrade Pyprotocols

Later, developers thought Setuptools development was too slow, fork out the distribute project, and then August 2013, distribute merged back to Setuptools 0.7.

Pip

Pip is a tool for installing and managing Python packages. It is an enhancement to the easy_install. The same can be downloaded automatically from the PyPI, install the package.

In Pip,

All required packages must be downloaded before installation, so there will not be a part installed, the other part is not installed

All installed packages will be tracked, so you can know why they are installed and can be uninstalled at the same time.

No need to use an egg file.

Easy to use:

Pip Install Pkg_name

Pip Uninstall Pkg_name

  • 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.