pip vs easy-install

Every Python developer must have used pip and easy_install to install Python modules. But it still remains a confusion “What’s the difference, anyhow? “. This blog post is to give you clear understanding of which one to use.

Key Terms:

First of all I would like to explain few terms for Python beginners.

  • pip – pip is a tool for installing Python packages from the Python Package Index. Starting with Python 3.4, it is included by default with the Python binary installers.
  • easy_install – It is a package manager for Python that provides a standard format for distributing Python programs and libraries (based on the Python Eggs format).
  • Python Package Index (PyPI) – The official third-party software repository for the Python programming language.
  • Setuptools: Setuptools is a package development library designed to facilitate packaging Python projects by enhancing the Python standard library distutils (distribution utilities).

How to install a Python module ?

  • The most basic way to install a package is to download the source code and run ‘python setup.py install’ inside the package directory.

#wget https://pypi.python.org/packages/source/m/mechanize/mechanize-0.2.5.tar.gz#md5=32657f139fc2fb75bcf193b63b8c60b2
#tar -xvzf mechanize-0.2.5.tar.gz
#cd mechanize-0.2.5
#python setup.py install

  • Second way to install module is using easy_install (default Python package manager).

#easy_install mechanize
Searching for mechanize
Reading https://pypi.python.org/simple/mechanize/
Best match: mechanize 0.2.5
Downloading https://pypi.python.org/packages/source/m/mechanize/mechanize-0.2.5.zip#md5=a497ad4e875f7506ffcf8ad3ada4c2fc
Processing mechanize-0.2.5.zip
Writing /tmp/easy_install-FiMleV/mechanize-0.2.5/setup.cfg
Running mechanize-0.2.5/setup.py -q bdist_egg --dist-dir /tmp/easy_install-FiMleV/mechanize-0.2.5/egg-dist-tmp-SKWpzt
Adding mechanize 0.2.5 to easy-install.pth file
Installed /usr/local/lib/python2.7/site-packages/mechanize-0.2.5-py2.7.egg
Processing dependencies for mechanize
Finished processing dependencies for mechanize

  • Third way to install module is using pip

#pip install mechanize
Downloading/unpacking mechanize
Downloading mechanize-0.2.5.tar.gz (383kB): 383kB downloaded
Running setup.py egg_info for package mechanize
Installing collected packages: mechanize
Running setup.py install for mechanize
Successfully installed mechanize
Cleaning up...

How pip is better than easy_install ?

Now as a Python developer I would recommend pip over easy_install. To illustrate, I have list down some points which shows how pip is better than easy_install.

  1. Partial-completed installation:Pip downloads source code and builds it whereas easy_install downloads binaries. This is most crucial point which signifies that partially-completed installation doesn’t occur in case of pip.

    Easy_install doesn’t do a whole lot of up-front checking to make sure it’ll actually be able to install both the requested package and the dependencies, and this can lead to problems if something in the dependency chain ends up uninstallable.

    Meanwhile, pip looks before it leaps, can bail out early if it’s not going to be able to install your package and will leave behind a useful log file explaining what went wrong.

  2. Pip requirements file: This is really the killer feature pip has, because it means you can set up a simple plain text file specifying a list of packages (and just as important, which versions of which packages), and get pip to install them all and your project is ready to be used on different machine within seconds.To see how handy this can be, let’s take a simple example:

    requirements.txt

    BeautifulSoup==3.2.0
    Django==1.3
    Fabric==1.2.0
    Jinja2==2.5.5
    South==0.7.3

    #pip install requirements.txt

  3. Integration with virtualenv: Naturally pip integrates quite nicely with virtualenv. Normally, when working in an active virtualenv, Python packaging/installation tools (pip included) will install into that virtualenv, but pip also lets you specify a virtualenv to install into (using the -E flag), and ceate a new virtualenv and install into it.
    Let’s take a simple example: suppose you have an application which runs fine against the current Django release (1.0.2), and you want to play around a bit with the Django development trunk to try out a new feature. You could create a requirements file specifying docutils (so the automatic Django documentation will work) and the Subversion URL for Django trunk:

    docutils==0.5
    -e svn+http://code.djangoproject.com/svn/django/trunk#egg=Django

    Save this into a file named, say, django-requirements.txt. Then (assuming you have pip and virtualenv installed), run the following:

    pip install -E django-trunk -r django-requirements.txt
    source django-trunk/bin/activate

How easy_install is better than pip ?

Only one positive thing which I found in easy_install over pip is in windows environment. A number of packages on PyPI have binary eggs for Windows uploaded. For example, on Windows easy_install lxml will work fine and install precompiled binaries, whereas pip install lxml will try to build from source and almost certainly fail unless the user has gone to a great deal of trouble to setup a Visual Studio environment and have a working build of libxml2.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s