2017-10-09 61 views
1

目標:在我的RHEL服務器上安裝python 2.7.14和python 3.6並使用pip2/pip3來管理這兩個版本。使用pip管理RHEL7上的兩個python 2.7版本

注意:儘管此服務器缺少互聯網連接,我可以單獨下載並將它們上傳到此服務器。

我最近在虛擬機上安裝了RHEL 7.2,默認安裝了python 2.7.5。 我決定通過並行安裝2.7.14(使用make altinstall方法並保持現有的2.7.5完整)來升級。我還打算在將來將所有現有的Python代碼移植到它上面,同時安裝了python 3.6。

當我嘗試爲Python 2.7.14或任何庫(如稍後會看到的)安裝pip時,就會出現問題。

我第一次做PIP的使用easy_install:

[[email protected] 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 

這將安裝PIP爲Python 2.7.5和3.6而不是蟒蛇2.7.14。

接下來,我下載了get-pip.py:

這被安裝罰款蟒蛇2.7.5而不是蟒蛇2.7.14:

[[email protected] 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 

[[email protected] 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:

[[email protected] 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 

[[email protected] 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

[[email protected] 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腳本的工作。

謝謝。

回答

0

正如它在這裏提到的那樣:https://pip.pypa.io/en/latest/installing我做了一個本地安裝的pip,但是爲python 2.7.14調用了python可執行文件。

下載車輪,setuptools的和PIP的.whl文件,然後運行以下:

[[email protected] 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將安裝包蟒蛇2.7.14現在。

通過安裝xlrd庫測試了這個(注意 - 我在本地目錄中xlrd壓縮包):

[[email protected] 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 

[[email protected] 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 
>>> 
相關問題