使用pip在RHEL7上管理两个版本的python 2.7

时间:2017-10-09 16:53:32

标签: python-2.7 python-3.x pip

目标:在我的RHEL服务器上安装python 2.7.14和python 3.6,并使用pip2 / pip3来管理它们。

注意:虽然此服务器没有互联网连接,但我可以单独下载并将它们上传到此服务器。

我最近在VM上安装了RHEL 7.2,默认安装python 2.7.5。 我决定通过并行安装2.7.14来升级它(使用make altinstall方法并保持现有的2.7.5不变)。还安装了python 3.6,因为我计划将来将所有现有的python代码移植到它。

当我尝试为Python 2.7.14或任何库安装pip时会出现问题(正如您稍后会看到的那样)。

我首先做了一个easy_install的pip

[root@VMW01 bin]# easy_install pip
Searching for pip
Best match: pip 9.0.1
Adding pip 9.0.1 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip3 script to /usr/local/bin
Installing pip3.5 script to /usr/local/bin

Using /usr/local/lib/python3.6/site-packages
Processing dependencies for pip
Finished processing dependencies for pip

这将安装python 2.7.5和3.6的pip,但不安装python 2.7.14。

接下来,我下载了get-pip.py:

这适用于python 2.7.5但不适用于python 2.7.14:

[root@VMW01 pshah]# python get-pip.py
Collecting pip
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 978kB/s
Collecting wheel
  Downloading wheel-0.30.0-py2.py3-none-any.whl (49kB)
    100% |████████████████████████████████| 51kB 9.2MB/s
Installing collected packages: pip, wheel
Successfully installed pip-9.0.1 wheel-0.30.0

[root@VMW01 pshah]# /usr/local/bin/python2.7 get-pip.py
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting pip
  Could not fetch URL https://pypi.python.org/simple/pip/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
  Could not find a version that satisfies the requirement pip (from versions: )
No matching distribution found for pip

这似乎缺乏SSL库。

首先,我使用yum安装了这个:

[root@VMW01 pshah]# yum install openssl
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Package 1:openssl-1.0.1e-42.el7_1.9.x86_64 already installed and latest version
Nothing to do

[root@VMW01 pshah]# yum install openssl-devel
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Package 1:openssl-devel-1.0.1e-42.el7_1.9.x86_64 already installed and latest version
Nothing to do

其次,这似乎适用于python 2.7.5

[root@VMW01 pshah]# python
Python 2.7.5 (default, Oct 11 2015, 17:47:16)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>>

我太过分了吗?我应该使用2.7.5和python 3.6的默认安装吗?

我知道virtualenv可能是一个解决方案,但我不知道如何让它与Apache执行python脚本一起工作。

感谢。

1 个答案:

答案 0 :(得分:0)

正如它在这里提到的那样:https://pip.pypa.io/en/latest/installing我做了一个本地安装的pip,但为python 2.7.14调用了python可执行文件。

下载了wheel,setuptools和pip的.whl文件,然后运行以下内容:

[root@VMW01 pshah]# /usr/local/bin/python2.7 get-pip.py --no-index --find-link=.
Collecting pip
Collecting setuptools
Collecting wheel
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-9.0.1 setuptools-36.5.0 wheel-0.30.0

我相信调用pip2.7会立即安装python 2.7.14的软件包。

通过安装xlrd库进行测试(注意 - 我在本地目录中有xlrd tarball):

[root@VMW01 pshah]# pip2.7 install xlrd-1.1.0.tar.gz
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Processing ./xlrd-1.1.0.tar.gz
Building wheels for collected packages: xlrd
  Running setup.py bdist_wheel for xlrd ... done
  Stored in directory: /root/.cache/pip/wheels/b9/dc/43/e6acfa12bc48cdf3654dd7f44c66880548ea0322324bc6095f
Successfully built xlrd
Installing collected packages: xlrd
Successfully installed xlrd-1.1.0

[root@VMW01 pshah]# /usr/local/bin/python2.7
Python 2.7.14 (default, Oct  6 2017, 18:31:52)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import xlrd
>>>