CentOS 7安裝Python 3.6,pip3報錯問題__Python

來源:互聯網
上載者:User

在CentOS 7上安裝Python3.6.3後,在使用pip命令時報如下錯誤

Traceback (most recent call last):  File "/usr/Python3.6.3/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main    status = self.run(options, args)  File "/usr/Python3.6.3/lib/python3.6/site-packages/pip/commands/search.py", line 45, in run    pypi_hits = self.search(query, options)  File "/usr/Python3.6.3/lib/python3.6/site-packages/pip/commands/search.py", line 62, in search    hits = pypi.search({'name': query, 'summary': query}, 'or')  File "/usr/Python3.6.3/lib/python3.6/xmlrpc/client.py", line 1112, in __call__    return self.__send(self.__name, args)  File "/usr/Python3.6.3/lib/python3.6/xmlrpc/client.py", line 1452, in __request    verbose=self.__verbose  File "/usr/Python3.6.3/lib/python3.6/site-packages/pip/download.py", line 775, in request    headers=headers, stream=True)  File "/usr/Python3.6.3/lib/python3.6/site-packages/pip/_vendor/requests/sessions.py", line 522, in post    return self.request('POST', url, data=data, json=json, **kwargs)  File "/usr/Python3.6.3/lib/python3.6/site-packages/pip/download.py", line 386, in request    return super(PipSession, self).request(method, url, *args, **kwargs)  File "/usr/Python3.6.3/lib/python3.6/site-packages/pip/_vendor/requests/sessions.py", line 475, in request    resp = self.send(prep, **send_kwargs)  File "/usr/Python3.6.3/lib/python3.6/site-packages/pip/_vendor/requests/sessions.py", line 596, in send    r = adapter.send(request, **kwargs)  File "/usr/Python3.6.3/lib/python3.6/site-packages/pip/_vendor/cachecontrol/adapter.py", line 47, in send    resp = super(CacheControlAdapter, self).send(request, **kw)  File "/usr/Python3.6.3/lib/python3.6/site-packages/pip/_vendor/requests/adapters.py", line 497, in send    raise SSLError(e, request=request)pip._vendor.requests.exceptions.SSLError: Can't connect to HTTPS URL because the SSL module is not available.


是因為沒有正確配置ssl的原因,經過多次實驗,總結一下正確安裝步驟。

安裝步驟:

1. 下載Python 3.6.3

https://www.python.org/downloads/source/

2. 解壓縮

.xz檔案需要用xz工具解壓縮,先安裝xz

sudo yum install xzxz d Python-3.6.3.tar.xztar xvf Python-3.6.3.tar

3. 下載/安裝 openssl和openssl-devel。沒有wget的可通過yum install wget安裝

wget https://www.openssl.org/source/openssl-1.1.0g.tar.gz
在CentOS 7的最小安裝時,會預設安裝openssl,但是我沒找到安裝的lib路徑,所以就將其卸載了,自己裝,因為路徑在安裝Python3.6時需要用到。卸載openssl的命令:

sudo yum erase openssl

安裝openssl:

tar zxvf openssl-1.1.0g.tar.gzcd openssl-1.1.0g./config --prefix=/usr/local/openssl

make

make install

其中 --prefix後的路徑就是將要安裝的目錄,記住下面要用到。

下載openssl-devel並安裝

sudo yum install openssl-devel

4. 添加lib讀取路徑

sudo vi /etc/ld.so.conf

在最後添加一行

/usr/local/openssl/lib
這個路徑就是剛才安裝openssl的路徑。然後執行下面的命令使其生效

sudo ldconfig

5. 修改Python安裝包裡的Modules/Setup.dist檔案,將ssl注釋掉的部分開啟,修改後內容如下:

# Socket module helper for SSL support; you must comment out the other# socket line above, and possibly edit the SSL variable:SSL=/usr/local/openssl_ssl _ssl.c \        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \        -L$(SSL)/lib -lssl -lcrypto

其中SSL=後面的路徑是你實際安裝openssl的路徑


6. 配置安裝

./configure --prefix=/usr/Python3.6.3
make
make install

如果在安裝過程中,報找不到libssl.so.1.1的錯誤,請檢查第3步和第4步的配置。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.