Python Medium package management tools (Easy_install and PIP usage)

Source: Internet
Author: User
Tags curl redis virtual environment virtualenv

Turn from: http://jiayanjujyj.iteye.com/blog/1409819

Just started to learn python, in looking at the document and other people's blog to introduce the installation package with Easy_install, Setuptools, some use Pip,distribute, then what is the relationship between these tools, look at the following picture will understand


It can be seen that distribute is replaced by Setuptools, and Pip is Easy_install.

About these package tools can refer to Http://guide.python-distribute.org/installation.html#installing-pip

Here's a brief introduction:

Distribute is an enhancement to the standard library Disutils module, and we know that disutils is primarily used to make it easier to package and distribute packages, especially to other packages that have dependencies.

Distribute was created because the Setuptools package was no longer maintained.

Install distribute

You can install distribute via distribute_setup.py, or you can install it via Easy_install, Pip, source file, but using distribute_setup.py to install is the simplest and most popular way

$ curl-0 http://python-distribute.org/distribute_setup.py
$ sudo python distribute_setup.py

The PIP is the tool that installs the Python package, provides the installation package, lists the packages that have been installed, upgrades the packages, and uninstalls the package features.

The PIP is a replacement for Easy_install and provides the same easy_install as the lookup package, so packages that can be installed using Easy_install can also be installed using the PIP.

Install PIP

The PIP can be installed through a source code package, Easy_install, or script.

Here are the various installation methods:

Source code Method:

$ wget http://pypi.python.org/packages/source/p/pip/pip-0.7.2.tar.gz (replace with latest package)
$ tar xzf pip-0.7.2.tar.gz
$ CD pip-0.7.2
$ python setup.py install

Easy_install:

$ easy_install pip

get_pip.py script:

$ curl-0 https://raw.github.com/pypa/pip/master/contrib/get-pip.py
$ sudo python get-pip.py

OK, let's take a look at the use of PIP

Install package

$ pip Install Markdown

list the installed packages

$ pip Freeze

install a specific version of package

Specify a version number by using = =, >=, <=, <.

$ pip Install ' markdown<2.0 '

$ pip Install ' markdown>2.0,<2.0.3 '

Upgrade Package

Upgrade package to the current version, you can use-U or--upgrade

$ pip Install-u markdown

Uninstall Package

$ pip Uninstall Markdown

Query Package

Pip Search "Markdown"

PS--Package after installation of the Py file path:/usr/local/lib/python2.7/dist-packages



Turn from: http://www.yeolar.com/note/2012/08/18/setuptools-pip-virtualenv/

Introduction to several Python configuration tools: Setuptools, Pip, virtualenv

This article quickly summarizes several common Python configuration tools, including Setuptools, Pip, and virtualenv.

Setuptools

Setuptools manages Python's Third-party package, installs the package to Site-package, and installs the package suffix generally. Egg, which is actually in zip format. The default download package from Http://pypi.python.org/pypi is able to resolve the Python package dependencies.

After installing the Setuptools, you can install the package with the Easy_install command, with a variety of installation options.

# easy_install PACKAGE #          normal installation
# Easy_install/home/yeolar/pkg/package.egg # Install from a local or network file system
# Easy_install http://trac-hacks.org/svn/iniadminplugin/0.11/# Install from the specified download path
# Easy_install http://pypi.python.org/simple/ PACKAGE/PACKAGE-0.1.2.4.TAR.GZ # is installed from the URL source package, provided that the root directory in the package-0.1.2.4.tar.gz package must include the setup.py file
# easy_install-f Http://pypi.python.org/simple/PACKAGE # Search the package from the Web, and automatically install
# easy_install package==0.1.2.1 # To specify the version of the package, If the specified version is higher than the currently installed version, the

# easy_install-u PACKAGE       # is upgraded to the latest version and will be upgraded to the latest version without a specified version
# easy_install-u package== 0.1.2.2 # Upgrade to specified version

# easy_install-m PACKAGE       # Uninstall package, uninstall and delete legacy files manually
Pip

The PIP is also a package management tool that is similar to Setuptools and automatically installs a PIP if you use Virtualenv.

# pip Install PACKAGE #           installation package
# pip-f URL install PACKAGE    # Download installation package from specified URL
# pip-u install PACKAGE        # Upgrade Package
virtualenv

Virtualenv is a python environment configuration and switching tool that can be used to configure multiple Python runtime environments and isolate the Python environment in the system, known as the sandbox. The benefits of sandboxing include: Resolving version dependencies between libraries, such as different applications on the same system depending on the same library version. Resolve permissions restrictions, such as you do not have root privileges. Try new tools without worrying about polluting the system environment.

$ virtualenv Py-for-web

This creates a Python virtual environment called Py-for-web, which in effect clones a Python environment. You can then use the source Py-for-web/bin/activate command to update the terminal configuration and modify the environment variables. The next operation will only affect the py-for-web environment, you can use the PIP command here to install the package, of course, can also be directly installed.

$ source Py-for-web/bin/activate    # Enable virtual Environment
$ deactivate                        # Exit Virtual Environment

There is a virtualenv-sh package, the virtualenv did some terminal command enhancements. After installation, add the configuration in ~/.BASHRC:

. /usr/local/bin/virtualenv-sh.bash

It provides several common commands such as:

Mkvirtualenv <env_name>     Create virtual Environment in $workon_home
rmvirtualenv <env_name>     Delete virtual environment
Workon [ <env_name>]         switch to a virtual environment
deactivate                  exit the virtual environment
Lsvirtualenvs               List all virtual Environments
cdvirtualenv [ SubDir]       into the corresponding directory of the virtual environment

The default value for the $WORKON _home is ${home}/.virtualenvs. Link: http://www.yeolar.com/note/2012/08/18/setuptools-pip-virtualenv/



Turn from: http://www.cnblogs.com/PandaBamboo/p/3180568.html

Python notes--using Easy_install for module/package Management

Today, when I read the previous project code, I found that the parameters of the Third-party modules used inside were quite bizarre and were always incorrect. After analysis, it is found that the Third-party modules that are installed by themselves are inconsistent with the version used by the project. In Python module/package management, you have to mention the Easy_install, its advantages, "who used to know" Ah ...

I. Installation of Easy_install

Please go to Http://pypi.python.org/pypi/setuptools to choose their own installation package, I chose the setuptools 0.6c11, another bamboo wind using 64-bit Python, so download the ez_setup.py Install it yourself. The document says it clearly. When the installation is complete, Easy_install is added to the environment variable. For example, on the CentOS of Bamboo wind, you can enter "Easy_install-h" directly at the command line to view the relevant help.

Second, use Easy_install to install the Third party module/package

Operation is quite simple, such as bamboo wind now want to install Tornado words, only need to enter "Easy_install Torando" can.
It is worth noting that the above situation is installed by default is the latest version provided by Https://pypi.python.org/pypi, which in some cases will cause unnecessary confusion.
Still taking tornado as an example, PyPI now offers a version of 3.1, but the Bamboo Wind reading project uses the 2.2.1, the difference between these two versions is still quite a lot.
Fortunately Easy_install provides the ability to install the specified version, such as "Easy_install tornado==2.2.1" to install Tornado 2.2.1.

Iii. How to manage internal easy_install

Easy_install for the third party module/package installation path, the default is Python site-packages, such as the Bamboo Wind is/usr/lib/python2.6/site-packages. You can find easy-install.pth files in this directory. This file contains a record of the modules/packages installed using Easy_install. You can also determine the version of the module/package currently in use from this file. Take the easy-install.pth of bamboo Wind as an example:

1 $ cat easy-install.pth
2 import sys; sys.__plen = len (sys.path)
3/setuptools-0.6c11-py2.6.egg
4./ Configobj-4.7.2-py2.6.egg
5/redis-2.7.2-py2.6.egg
6/tornado-2.2.1-py2.6.egg
7 import sys; new= Sys.path[sys.__plen:]; del Sys.path[sys.__plen:]; P=getattr (sys, ' __egginsert ', 0); Sys.path[p:p]=new; Sys.__egginsert = P+len (new)

From the file information, you can find the modules/packages that are currently installed and the relevant version information.

IV. Uninstall MODULE/Package

Easy_install Of course also provides the ability to uninstall modules/packages. However, it must be noted that the module/package must have relevant information in the easy-install.pth, in other words, that is, to use the Easy_install installation, you can uninstall. The commands are as follows: "Easy_install-m Redis", which will uninstall the Redis module in Python.

V. Installed modules/packages are egg files.

When installing a Third-party module/package, it is possible to find that a egg file is installed, such as "Redis-2.7.2-py2.6.egg". For the studious program apes, want to see its source code how to do it. Very simple, just need to execute the following unzip on it, "unzip Redis-2.7.2-py2.6.egg" can be extracted from the source code.

Vi. Other parameters of Easy_install

This paper is limited in length and cannot be introduced to all the parameters of Easy_install. In contrast, you can figure out how to use other parameters:

It is worth mentioning the "-D" parameter, you can specify the installation directory. This is very convenient for testing. For example, you can create a new TMP directory in which to install a number of modules/packages to test (at this point in the TMP directory will also generate a easy_install.pth file, the individual speculated that easy_install in the runtime will be all the PTH file enough time). When the test is complete, you only need to remove the TMP directory.

Of course, "-Z" and "-Z" are always packaged into zip files or always uncompressed.

I hope this article is helpful to everyone ^_^




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.