python2与python3安装在同一个服务器上(linux)

一、Python2一般的默认安装的为python2.7

二、python3安装
 Linux 安装python3.7.0

1、安装依赖包                                                                       

1)首先安装gcc编译器,gcc有些系统版本已经默认安装,通过  gcc --version  查看,没安装的先安装gcc,

yum -y install gcc

2)安装其它依赖包,(注:不要缺少,否则有可能安装python出错,python3.7.0以下的版本可不装 libffi-devel )

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel

2、下载python3.7.0源码,根据需求下载                                 

1)在https://www.python.org/ftp/python/中选择自己需要的python源码包,我下载的是python3.7.0

(大家也可以去https://www.python.org官网首页下载,找到downloads,就可以选择想要的版本下载了)

2)下载

wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz

 3)、解压Python-3.7.0.tgz

tar -zxvf Python-3.7.0.tgz

4、建立一个空文件夹,用于存放python3程序

mkdir /usr/local/python3

5、执行配置文件,编译,编译安装

cd Python-3.7.0
./configure --prefix=/usr/local/python3
make && make install

安装完成没有提示错误便安装成功了

7、建立软连接

ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3
python3 -m pip install --upgrade pip

总结报错解决

问题一:安装时报错ModuleNotFoundError: No module named '_ctypes'的解决办法

1、执行如下命令:

yum install libffi-devel 

2、从"./configure ..."重新安装

问题二:pip3 install时报错“pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.”

先安装openssl-dev,然后重新编译安装,只是在编译的过程中加入 --enable-optimizations

centos: 

先下载openssl最新版本

wget http://www.openssl.org/source/openssl-1.0.2r.tar.gz
tar zxvf openssl-1.0.2r.tar.gz
./config --prefix=/opt/openssl1.0.2r --openssldir=/opt/openssl1.0.2r/openssl no-zlib
make && make install
echo "/opt/openssl1.0.2r/lib" >> /etc/ld.so.conf
ldconfig -v

 这一步是清除编译好的源码

make clean 或者删除python解压的源码安装包

  

./configure --prefix=/usr/local/python3 --with-openssl=/opt/openssl1.0.2r/

 

make -j && make install

  

 

ubuntu:

sudo apt-get install libffi-dev

或者

sudo apt-get update
 
sudo apt-get upgrade
 
sudo apt-get dist-upgrade
 
sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus
 
sudo apt-get install build-essential libncursesw5-dev libgdbm-dev libc6-dev
 
sudo apt-get install zlib1g-dev libsqlite3-dev tk-dev
 
sudo apt-get install libssl-dev openssl
 
sudo apt-get install libffi-dev

centos7

yum install libffi-devel -y

  

posted @ 2021-08-06 10:22  vekair  阅读(262)  评论(0编辑  收藏  举报