笔者用全新的一台虚拟机安装Python3.x版本遇到的一些问题,记录一下方便以后大家遇到同样问题可参考解决。
[root@dawn ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@dawn ~]# uname -r
6.3.2-1.el7.elrepo.x86_64
1). wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
创建一个安装文件位置
2). mkdir -p /usr/local/python3
进入解压后的目录,编译安装
3). cd Python-3.6.1
./configure --prefix=/usr/local/python3
make
make install
或者 make && make install
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
# vim ~/.bash_profile
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# source ~/.bash_profile
python3 -V
pip3 -V
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] 错误 1
在重新编译之前还需要在解压源文件中修改Modules/Setup.dist文件,将
#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
这行的注释去掉
zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
安装 zlib-devel
yum -y install zlib-devel
笔者用pip3安装psutil模块的时候出现了下面的报错:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting psutil
Could not fetch URL https://pypi.python.org/simple/psutil/: 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 psutil (from versions: )
No matching distribution found for psutil
1、使用rpm -aq|grep openssl命令查询openssl是否正确安装,发现缺少openssl-devel包
2、安装openssl-devel包
yum install -y openssl-devel
3、重新编译安装python
./configure --prefix=/usr/local/python3
make
make && make install
4、测试
[root@dawn Python-3.6.1]# pip3 install psutil
Collecting psutil
Downloading https://files.pythonhosted.org/packages/d6/0f/96b7309212a926c1448366e9ce69b081ea79d63265bde33f11cc9cfc2c07/psutil-5.9.5.tar.gz (493kB)
100% |████████████████████████████████| 501kB 2.6MB/s
Installing collected packages: psutil
Running setup.py install for psutil ... done
Successfully installed psutil-5.9.5
5、升级pip
[root@dawn Python-3.6.1]# pip3 install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/a4/6d/6463d49a933f547439d6b5b98b46af8742cc03ae83543e4d7688c2420f8b/pip-21.3.1-py3-none-any.whl (1.7MB)
100% |████████████████████████████████| 1.7MB 159kB/s
Installing collected packages: pip
Found existing installation: pip 9.0.1
Uninstalling pip-9.0.1:
Successfully uninstalled pip-9.0.1
Successfully installed pip-21.3.1
以上安装Python3.x方法,笔者使用过好多次供大家参考;