sting_roc sting_roc - 1 year ago 74
Python Question

How to install pip with two python version exist on CentOS 6.4?

I have a CentOS 6.4 which the default python version is 2.6.

I want to run a virtualenv at python 2.7, so first I try to install python 2.7.

yum install python27

Then I run

virtualenv -p /usr/bin/python2.7 ./venv

Then the output shows that it try to get setuptools from pypi, but my environment can not reach I have update the ~/.pip/pip.conf to use a available local source but the virtualenv still get pip from the This is one of the things I get confused.

I check the /usr/lib/python2.7/, the site-packages is empty while /usr/lib/python2.6/ is not. So When I use python 2.7, it has nothing available. When I use the default python, it has pip tools installed, it does not need to get it from

How can I install pip for python 2.7 individually?

Previous I install pip by

yum install python-setuptools
yum install python-pip

Answer Source

The second question, how to install pip for python2.7 individually can be solved as the following:

Download python source code of the specific version and install it at /usr/local

tar xf Python-2.7.6.tar.xz
cd Python-2.7.6
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall

Then install setuptools and pip

Install easy_install (prepare beforehand)


Install pip

easy_install-2.7 pip

easy_intall-2.7 pip need to visit the internet, in my environment I get the pip source file and use "python2.7 install".

pip2.7 install [packagename]

In my environment I update .pip/pip.conf to use an internal pip source.

(code above take python 2.7 as an example)

To see the details you can check the following url:

The first question, when creating a new virtual environment, virtualenv will install setuptools for this environment. If python version is not assigned, it use the system default python and default pip. If pip is not find, then try to get it from

In my environment, after python2.7 and pip2.7 installed, when trying to create a new virtualenv, it still get pip from, I guess that virtualenv does not find the relation between python2.7 and pip2.7.

If you can visit, that is fine.

If you are at an internal environment that can not visit, virtualenv provides -extra-search-dir and --never-download command. So you can prepare the setuptools beforehand, copy it from U-disk,using scp, or other solutions.

Move setuptools-0.6c11-py2.7.egg to /usr/local/bin.

Finally we can use virtualenv by

virtualenv -p /usr/local/bin/python2.7 --extra-search-dir /usr/local/bin/ --never-download venv