简体   繁体   中英

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 pypi.python.org. I have update the ~/.pip/pip.conf to use a available local source but the virtualenv still get pip from the pypi.python.org. 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 pypi.python.org.

How can I install pip for python 2.7 individually?

Previous I install pip by

yum install python-setuptools
yum install python-pip

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

wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
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 ez_setup.py beforehand)

python2.7 ez_setup.py

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 setup.py 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:

http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/

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 pypi.python.org.

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

If you can visit pypi.python.org, that is fine.

If you are at an internal environment that can not visit pypi.python.org, 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM