I have downloaded, compiled and installed Python 2.7 on CentOS.

I would like to download and install easy_install (and pip) for it but I am a little bit confused as to how to do that.

How can I proceed to get setuptools and easy_install and pip using a non-default Python installation installed in /usr/local/?


If you have a need for specific versions of Python, Perl, Ruby etc. you should really get in the habit of using systems such as the following to setup your own local versions of these interpreters:


This project used to be known as pythonbrew, but is now known as pyenv. To install it you need to clone a copy of it into your $HOME directory like so:

$ git clone git://github.com/yyuu/pyenv.git .pyenv
Cloning into .pyenv...
remote: Counting objects: 2207, done.
remote: Compressing objects: 100% (617/617), done.
remote: Total 2207 (delta 1489), reused 2172 (delta 1462)
Receiving objects: 100% (2207/2207), 358.75 KiB, done.
Resolving deltas: 100% (1489/1489), done.

Now add the setup of pyenv to your ~/.bashrc file:

$ echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> .bashrc
$ echo 'eval "$(pyenv init -)"' >> .bashrc

You can see the usage of pyenv:

$ pyenv 
pyenv 0.4.0-20130613-17-ge1ea64b
Usage: pyenv <command> [<args>]

Some useful pyenv commands are:
   commands    List all available pyenv commands
   local       Set or show the local application-specific Python version
   global      Set or show the global Python version
   shell       Set or show the shell-specific Python version
   install     Install a Python version using the python-build plugin
   uninstall   Uninstall a specific Python version
   rehash      Rehash pyenv shims (run this after installing executables)
   version     Show the current Python version and its origin
   versions    List all Python versions available to pyenv
   which       Display the full path to an executable
   whence      List all Python versions that contain the given executable

See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/yyuu/pyenv#readme

You can see what versions are available:

$ pyenv versions
* system (set by /home/saml/.pyenv/version)

Now let's install Python 3.2.5:

$ pyenv install 3.2.5
Downloading Python-3.2.5.tgz...
-> http://yyuu.github.io/pythons/ed8d5529d2aebc36b53f4e0a0c9e6728
Installing Python-3.2.5...
Installed Python-3.2.5 to /home/saml/.pyenv/versions/3.2.5

Downloading setuptools-0.9.5.tar.gz...
-> https://pypi.python.org/packages/source/s/setuptools/setuptools-0.9.5.tar.gz
Installing setuptools-0.9.5...
Installed setuptools-0.9.5 to /home/saml/.pyenv/versions/3.2.5

Downloading pip-1.3.1.tar.gz...
-> http://yyuu.github.io/pythons/cbb27a191cebc58997c4da8513863153
Installing pip-1.3.1...
Installed pip-1.3.1 to /home/saml/.pyenv/versions/3.2.5

Rebuild our environment to incorporate new install:

$ pyenv rehash

Now we should see 2 versions available, system is still the default (*):

$ pyenv versions
* system (set by /home/saml/.pyenv/version)

Let's switch to 3.2.5:

$ pyenv which python

$ pyenv global 3.2.5

$ pyenv which python

$ pyenv versions
* 3.2.5 (set by /home/saml/.pyenv/version)

virtualenv & virtualenvwrapper

These 2 Python modules provide you mechanisms for maintaining separate workspaces where site-packages can be maintained. They a good option if you want to isolate sets of Python modules into sets and associate them to a given Python application. They're a little awkward to use but do the job.

There's a screencast that shows how to use virtualenvwrapper as well. For Python I'd setup virtualenv first, followed by virtualenvwrapper.


$ sudo easy_install virtualenv
$ easy_install virtualenvwrapper

At this point the 2 Python modules have been installed. From here you need to setup your environment, add the following to your $HOME/.bashrc file:

export WORKON_HOME=$HOME/.virtualenvs
source /usr/bin/virtualenvwrapper.sh

Now re-source your .bashrc:

$ source ~/.bashrc

Now you're ready to list your work environments:

$ workon

You don't have any yet, so let's create one, we'll call it "temp":

$ mkvirtualenv temp
New python executable in temp/bin/python
Installing setuptools................done.

Now when we re-list our worksets using workon:

(temp)$ workon

Notice the prompt has changed so that the workspace is prefixed in front of your prompt. Now, to remove it:

(temp)$ rmvirtualenv temp
Removing temp...
ERROR: You cannot remove the active environment ('temp').
Either switch to another environment, or run 'deactivate'.

Can't so deactivate it, and your prompt is back to normal:

(temp)$ deactivate

Now try to remove it:

$ rmvirtualenv temp
Removing temp...

Now let's recreate it again, and cd to our workspace:

$ mkvirtualenv temp
New python executable in temp/bin/python
Installing setuptools................done.

(temp)$ cdvirtualenv 
(temp)$ ls
bin  include  lib  lib64

Now check out the "temp" workspace site-packages:

$ cdsitepackages 
(temp)$ pwd

Now let's install a Python module, smooshy, first let's search for it using pip:

(temp)$ pip search smooshy
smooshy                   - Automatic lossless image compression

Now install it:

(temp)$ pip install smooshy
Downloading/unpacking smooshy
  Downloading smooshy-1.tar.gz
  Running setup.py egg_info for package smooshy

Requirement already satisfied (use --upgrade to upgrade): simplejson in /usr/lib64/python2.7/site-packages (from smooshy)
Installing collected packages: smooshy
  Running setup.py install for smooshy
    changing mode of build/scripts-2.7/smooshy from 664 to 775

    changing mode of /home/saml/.virtualenvs/temp/bin/smooshy to 775
Successfully installed smooshy
Cleaning up...

To confirm where it was installed:

(temp)$ which smooshy
  • 1
    pyenv and normal virtualenvwraper do not smoothly work together, for that you need a special python-virtualenvwrapper – Anthon Dec 4 '13 at 20:12
  • I don't think recommending pyenv is a good thing. Today statistics on pypi.python.org for pyenv: 0 downloads in the last day, 0 downloads in the last week, 0 downloads in the last month. Compare this with 11677 downloads in the last day, 61734 downloads in the last week, 294057 downloads in the last month for virtualenv. – Piotr Dobrogost Dec 5 '13 at 0:10
  • @PiotrDobrogost - Not sure if you're familiar with my style of answers but I often try and highlight all the possible methods to solving something. I like to present everything in a canonical answer, when possible. I show them both in an even light and leave it to the readers to pick which method(s) work best for their particular situations. – slm Dec 5 '13 at 2:58

You should first download ez_setup.py and then run it with your newly compiled python:

wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
sudo /usr/local/bin/python ez_setup.py

then run:

wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
sudo /usr/local/bin/python get-pip.py

based on this


You can set an alias in your home folder for python so that it "points" to /usr/local/bin/python, for example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.