Python3安装问题汇总

文章详细记录了在CentOS7系统中安装Python3.6.1的过程,包括下载、编译、安装以及遇到的zlib和ssl模块缺失的问题。作者提供了解决问题的步骤,如安装zlib-devel和openssl-devel,并重新编译Python。此外,还解决了pip3安装psutil模块时因缺少ssl支持导致的错误。
摘要由CSDN通过智能技术生成

笔者用全新的一台虚拟机安装Python3.x版本遇到的一些问题,记录一下方便以后大家遇到同样问题可参考解决。

一、系统信息

1、以下两条命令可以查看服务器系统版本和内核版本

[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

2、python3下载安装:

1). wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz

创建一个安装文件位置

2). mkdir -p /usr/local/python3

3、解压Python安装包

进入解压后的目录,编译安装

3). cd Python-3.6.1
  ./configure --prefix=/usr/local/python3
  make
  make install    
  或者 make && make install

4、建立python3的软链

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

5、建立pip3的软链接

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

6、并将/usr/local/python3/bin加入PATH

#  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

7、检查Python3及pip3是否正常可用

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方法,笔者使用过好多次供大家参考;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小竹吟風

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值