Linux 安装多个版本的python

1、下载所需python版本。这里用的是python2.7.5和3.7.4

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

2、编译安装python前需要保证系统已安装一下库

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

3、解压源码包

tar -zxvf Python-2.7.5.tgz
tar -zxvf Python-3.7.4.tgz

4、编译安装

#V2.7.5

cd Python-2.7.5
./configure --prefix=/usr/local/python2.7
make && make install

#V3.7.4

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

注:--prefix 用户指定python的安装路径

5、安装好以后发现 /usr/local/bin 下出现了一下文件。(此处截图为3.7.4版本截图)

Linux 安装多个版本的python_第1张图片

6、建立软连接(如果 /usr/bin里有则可以省略此步)

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

7、安装不同版本的pip

wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py #安装python2.7的pip
python3 get-pip.py #安装python3.7的pip3

8、给pip建立软连接

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

 

你可能感兴趣的:(Linux,python安装,pip安装)