简体   繁体   中英

CentOS: Two Versions of Python and Packages

I'm no Python or CentOS (CloudLinux 6.6 + WHM/cPanel) expert, but I'm trying to install an updated version of Python under CentOS with some extra packages and keeping the system version working.

I managet to get Python 2.7 installed by:

yum groupinstall -y development
yum install -y zlib-dev openssl-devel sqlite-devel bzip2-devel    
wget https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
tar xzf Python-2.7.6.tgz
cd Python-2.7.6
./configure --prefix=/usr/local
make
sudo make alt install

If I run python I get Python 2.6.6 and python2.7 gives me Python 2.7.6 . Yum also seems to work fine, so I guess I didn't break the system.

Now, my problem is, I need to get Twistd installed on the Python 2.7, and it needs zope.interface also.

How can I install both of them on the Python 2.7 installation at /usr/local ?

Also, after that if I want to run a setup for a twistd plugin and run it under the python 2.7 how should I do it?

Thank you.

I would use virtualenv for this. Here is the steps that you can follow:

  1. install virtualenv :

    sudo yum install virtualenv

    wget bootstrap.pypa.io/get-pip.py

    python get-pip.py --user

    pip install virtualenv

  2. create a virtual env for you app, and precise the python binary you want to use:

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

  3. Activate it:

    source ~/venv/bin/activate

  4. now you are in you virtual env. every python command that you will run will use the python2.7 specified in the command line. Also you can now use pip to install python packages (again, only in your virtual env folder):

    pip install Twisted

Dependencies will be handled automatically.

Note that you may need some dev rpm packages as Twisted needs some C compilation.

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