centos7 安裝 python3


起因

為了試試 bpytop 進行了如下折騰 (所有操作均在虛擬機內完成)

先上成果圖
PS: 確實 酷!:)

bpytop-view
bpytop-option


安裝 python3


1.下載安裝包
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
or
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz --no-check-certificate

2.解壓

tar -xvJf  Python-3.7.0.tar.xz

3.編譯安裝

mkdir /usr/local/python3 #創建編譯安裝目錄
cd Python-3.7.0
./configure --prefix=/usr/local/python3  # ./configure --prefix=/usr/local/python3 --with-ssl
make && make install

編譯過程遇到的報錯&解決辦法

zipimport.ZipImportError: can't decompress data; zlib not available

ModuleNotFoundError: No module named '_ctypes'


4.創建軟連接

ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3

5.驗證

python3 -V
pip3 -V

參考:
https://www.cnblogs.com/anxminise/p/9650206.html
https://blog.csdn.net/blueheart20/article/details/72827666
https://blog.csdn.net/qq_42353939/article/details/94609591




后續:


pip3 無法正常使用,報錯如下:

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
[root@controller upload]# pip3 install --upgrade pip
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pip/
Could not fetch URL https://pypi.tuna.tsinghua.edu.cn/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.tuna.tsinghua.edu.cn', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
Requirement already up-to-date: pip in /usr/local/python3/lib/python3.7/site-packages (10.0.1)
You are using pip version 10.0.1, however version 21.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

處理:

# 下載 openssl 
wget https://files-cdn.cnblogs.com/files/luckjinyan/openssl-1.1.1g.tar.gz

tar -zxvf openssl-1.1.1g.tar.gz

cd openssl-1.1.1g/

# 編譯安裝
./config --prefix=/usr/local/openssl
make && make install

# 備份&替換舊的 openssl
mv /usr/bin/openssl /usr/bin/openssl.old
mv /usr/lib64/openssl /usr/lib64/openssl.old
mv /usr/lib64/libssl.so /usr/lib64/libssl.so.old
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
ln -s /usr/local/openssl/lib/libssl.so /usr/lib64/libssl.so
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
ldconfig -v // 建立動態鏈接

# 驗證
openssl version

# 重新編譯 python3
cd Python-3.7.0
./configure --prefix=/usr/local/python3 --with-openssl=/usr/local/openssl
make && make install

升級pip3並完成 bpytop 的安裝

[root@controller upload]# pip3 install --upgrade pip
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pip
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a4/6d/6463d49a933f547439d6b5b98b46af8742cc03ae83543e4d7688c2420f8b/pip-21.3.1-py3-none-any.whl (1.7MB)
    100% |████████████████████████████████| 1.7MB 538kB/s 
Installing collected packages: pip
  Found existing installation: pip 10.0.1
    Uninstalling pip-10.0.1:
      Successfully uninstalled pip-10.0.1
Successfully installed pip-21.3.1
[root@controller upload]# pip3 install psutil-5.8.0-cp37-cp37m-manylinux2010_x86_64.whl 
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Processing ./psutil-5.8.0-cp37-cp37m-manylinux2010_x86_64.whl
Installing collected packages: psutil
Successfully installed psutil-5.8.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
[root@controller upload]# pip3 install bpytop-1.0.67-py3-none-any.whl 
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Processing ./bpytop-1.0.67-py3-none-any.whl
Requirement already satisfied: psutil<6.0.0,>=5.7.0 in /usr/local/python3/lib/python3.7/site-packages (from bpytop==1.0.67) (5.8.0)
Installing collected packages: bpytop
Successfully installed bpytop-1.0.67
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
[root@controller upload]# 

參考:
https://www.jianshu.com/p/8e476eef43f7
https://www.cnblogs.com/luckjinyan/p/13124422.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM