在Linux中安装指定版本的Python
Centos系统
安装依赖包;
1
yum install zlib-devel bzip2-devel openssl-devel libffi-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc* make -y
去Python官网下载需要的Python版本至本地路径,这里以
Python3.8.13
为例安装;
淘宝Python镜像加速网站:https://npm.taobao.org/mirrors/python/1
wget https://registry.npmmirror.com/-/binary/python/3.8.13/Python-3.8.13.tgz
解压Python安装包;
1
tar zxvf Python-3.8.13
配置安装路径
切入到解压目录
1
cd ./Python-3.8.13
配置安装路径(这里配置的Python安装路径为/usr/local/python3,后续Python将会安装在此目录下)
1
./configure prefix=/usr/local/python3 --with-openssl=/usr/local/openssl
编译安装
1
make && make install
配置软连接以便全局使用
1
2ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3测试
1
2
3看是否可以运行
python3
pip3错误一:No module named ‘_ctypes’
yum install libffi-devel -y
cd Python-3.7.8/
make clean && make && make install
Ubuntu系统
- 安装依赖包:
1 | sudo apt install build-essential zlib1g-dev libbz2-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget |
- 下载需要安装的Python版本:
淘宝Python镜像加速网站:https://npm.taobao.org/mirrors/python/
1 | wget https://registry.npmmirror.com/-/binary/python/3.8.13/Python-3.8.13.tgz |
解压Python安装包;
1
tar zxvf Python-3.8.13
配置安装路径
切入到解压目录
1
cd ./Python-3.8.13
配置安装路径(这里配置的Python安装路径为/usr/local/python3,后续Python将会安装在此目录下)
1
sudo ./configure prefix=/usr/local/python3
编译安装
1 | sudo make && sudo make install |
- 配置软连接
1 | sudo ln -s /usr/local/python3/bin/python3 /usr/bin/python3 |
- 测试
1 | 看是否可以运行 |
- Title: 在Linux中安装指定版本的Python
- Author: Spring
- Created at : 2023-10-30 10:44:16
- Updated at : 2023-10-30 10:51:06
- Link: https://www.tecacc.com//post/install-python-in-linux-z2ot3ge.html
- License: This work is licensed under CC BY-NC-SA 4.0.