简体   繁体   English

CentOS:两种版本的Python和软件包

[英]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. 我不是Python或CentOS(CloudLinux 6.6 + WHM / cPanel)专家,但是我试图在CentOS下安装Python的更新版本,并提供一些额外的软件包,并保持系统版本正常运行。

I managet to get Python 2.7 installed by: 我设法通过以下方式安装了Python 2.7:

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 . 如果我运行python我会得到Python 2.6.6python2.7会给我Python 2.7.6 Yum also seems to work fine, so I guess I didn't break the system. Yum似乎也可以正常工作,所以我想我没有破坏系统。

Now, my problem is, I need to get Twistd installed on the Python 2.7, and it needs zope.interface also. 现在,我的问题是,我需要在python 2.7上安装Twistd,它也需要zope.interface

How can I install both of them on the Python 2.7 installation at /usr/local ? 如何在/usr/local的Python 2.7安装中安装它们两者?

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? 另外,在那之后,如果我想为扭曲的插件运行安装程序并在python 2.7下运行它,该怎么办?

Thank you. 谢谢。

I would use virtualenv for this. 我会为此使用virtualenv。 Here is the steps that you can follow: 您可以按照以下步骤操作:

  1. install virtualenv : 安装virtualenv

    sudo yum install virtualenv 须藤yum安装virtualenv

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

    python get-pip.py --user python get-pip.py --user

    pip install virtualenv pip安装virtualenv

  2. create a virtual env for you app, and precise the python binary you want to use: 为您的应用程序创建一个虚拟环境,并精确定义要使用的python二进制文件:

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

  3. Activate it: 激活它:

    source ~/venv/bin/activate 来源〜/ 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. 您将运行的每个python命令都将使用命令行中指定的python2.7。 Also you can now use pip to install python packages (again, only in your virtual env folder): 您现在还可以使用pip安装python软件包(同样,仅在您的虚拟env文件夹中):

    pip install Twisted 点安装Twisted

Dependencies will be handled automatically. 依赖关系将自动处理。

Note that you may need some dev rpm packages as Twisted needs some C compilation. 请注意,您可能需要一些dev rpm软件包,因为Twisted需要一些C编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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