在Linux中安装指定版本的Python

Spring Lv2

Centos系统

  1. 安装依赖包;

    1
    yum install zlib-devel bzip2-devel openssl-devel libffi-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc* make -y
  2. 去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
  3. 解压Python安装包;

    1
    tar zxvf Python-3.8.13
  4. 配置安装路径

    1. 切入到解压目录

      1
      cd ./Python-3.8.13
    2. 配置安装路径(这里配置的Python安装路径为/usr/local/python3,后续Python将会安装在此目录下)

      1
      ./configure prefix=/usr/local/python3 --with-openssl=/usr/local/openssl
  5. 编译安装

    1
    make && make install
  6. 配置软连接以便全局使用

    1
    2
    ln -s /usr/local/python3/bin/python3 /usr/bin/python3
    ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
  7. 测试

    1
    2
    3
    # 看是否可以运行
    python3
    pip3
    1. 错误一:No module named ‘_ctypes’

      yum install libffi-devel -y
      cd Python-3.7.8/
      make clean && make && make install

Ubuntu系统

  1. 安装依赖包:
1
sudo apt install build-essential zlib1g-dev libbz2-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
  1. 下载需要安装的Python版本:

   淘宝Python镜像加速网站:https://npm.taobao.org/mirrors/python/

1
wget https://registry.npmmirror.com/-/binary/python/3.8.13/Python-3.8.13.tgz
  1. 解压Python安装包;

    1
    tar zxvf Python-3.8.13
  2. 配置安装路径

    1. 切入到解压目录

      1
      cd ./Python-3.8.13
    2. 配置安装路径(这里配置的Python安装路径为/usr/local/python3,后续Python将会安装在此目录下)

      1
      sudo ./configure prefix=/usr/local/python3
  3. 编译安装

1
sudo make && sudo make install
  1. 配置软连接
1
2
sudo ln -s /usr/local/python3/bin/python3 /usr/bin/python3
sudo ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
  1. 测试
1
2
3
# 看是否可以运行
python3
pip3

  ‍

  • 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.
On this page
在Linux中安装指定版本的Python