python 3のインストール中に発生したsslの問題、No module named_ssl

3985 ワード

Python 3をインストールします.6.4
1 python 3をインストールします.6使用可能な依存
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++  openssl-devel
2 python公式サイトにダウンロードパスを見つけて、wgetでダウンロードします
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
3 tgzパッケージの解凍
tar -xf Python-3.6.5.tgz
4 pythonディレクトリへ
cd /Python-3.6.5/
5コンパイル、インストール
5.1ヒントSSLモジュールが見つからない
pythonのインストールが完了すると、sslモジュールが見つかりません.
[root@localhost ~]# python2.7.5
Python 2.7.5 (default, Jun 3 2013, 11:08:43) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
File "", line 1, in 
File "/usr/local/python27/lib/python2.7/ssl.py", line 60, in 
import _ssl # if we can't import it, let the error propagate
ImportError: No module named _ssl
>>>
5.2 pythonの再コンパイル(最後の4行のコメントを除く)
#  Setup  
vi /root/Python-3.6.5/Modules/Setup.dist
#      :
# Socket module helper for socket(2)
_socket socketmodule.c timemodule.c

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
5.3コンパイルインストール
./configure --prefix=/usr/local/python
make
make install
5.4テスト、正常に使用できます.
[root@localhost ~]# python
Python 3.6.4 (default, Jun 3 2013, 14:56:13) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>>
注意:古いバージョンを保持する必要がある場合は、6.7の2つのセクションを実行する必要はありません.
6古いバージョンのpython依存の名前を変更
ll /usr/bin | grep python

mv /usr/bin/python /usr/bin/python2.7
7古いソフトリンクを削除し、最新のpythonに新しいソフトリンクを作成する
rm -rf /usr/bin/python

ln -s /usr/local/bin/python3.6 /usr/bin/python

python -V
yumコマンドを使用してFile"/usr/bin/yum"、line 30 except KeyboardInterrupt,e:問題の原因:
yumパッケージ管理はpython 2を使用する.x書き、python 2.x python 3にアップグレードする.1.3以降、pythonバージョンの構文互換性による問題の解決策:yumプロファイルを変更し、pythonバージョンを以前の古いバージョンに移動
# vi /usr/bin/yum
#!/usr/bin/python2.7
urlgrabber-ext-downファイルを変更し、pythonバージョンを変更
# vi /usr/libexec/urlgrabber-ext-down
#!/usr/bin/python2.7
Could not fetch URL https://pypi.python.org/simple/six/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
pipをインストールする必要がある場合
関連ファイルのダウンロード
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
実行
/usr/local/python/bin/python3 get-pip.py
環境変数の追加
vim ~/.bash_profile
次のパラメータを追加
export PATH=/usr/local/python/bin:$PATH
保存source~/.bash_profile
テスト
実行
[root@huo ~]# python3
Python 3.6.5 (default, Apr  1 2018, 20:41:34)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
実行スクリプトは次のとおりです.
vim install_python.sh
#!/bin/bash
echo "        "
yum install -y openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc-c++ gcc openssl-devel

echo "     "
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz

echo "       "
tar -xf Python-3.6.5.tgz -C /root/  && cd /root/Python-3.6.5/

echo "  ssl  "
cat >> /root/Python-3.6.5/Modules/Setup.dist <> ~/.bash_profile
source ~/.bash_profile

echo "    ,   python3    "