ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

centos7 安装 python3

2021-11-03 23:34:56  阅读:304  来源: 互联网

标签:None local openssl centos7 usr https pip 安装 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

标签:None,local,openssl,centos7,usr,https,pip,安装,python3
来源: https://www.cnblogs.com/blame9/p/15504620.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有