Linux 安裝Python3.9和pip

Linux·Python · 2023-12-25 · 517 人浏览

在不同的Linux发行版上安装Python 3.9可能会有所不同。以下是在Debian、Ubuntu、Alpine和CentOS上安装Python 3.9的一般步骤:

在Debian和Ubuntu上安装Python 3.9:

  1. 使用apt获取依赖项

    sudo apt update
    sudo apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget
  2. 下载Python 3.9源代码

    wget https://www.python.org/ftp/python/3.9.9/Python-3.9.9.tgz
  3. 解压缩源代码并进入目录

    tar -xf Python-3.9.9.tgz
    cd Python-3.9.9
  4. 配置和安装

    ./configure --enable-optimizations
    make -j$(nproc)
    sudo make altinstall
  5. 验证安装

    python3.9 --version

在Alpine上安装Python 3.9:

  1. 更新包索引并安装依赖项

    apk update
    apk add build-base openssl-dev libffi-dev zlib-dev readline-dev ncurses-dev bzip2-dev gdbm-dev sqlite-dev
  2. 下载Python 3.9源代码

    wget https://www.python.org/ftp/python/3.9.9/Python-3.9.9.tgz
  3. 解压缩源代码并进入目录

    tar -xf Python-3.9.9.tgz
    cd Python-3.9.9
  4. 配置和安装

    ./configure --enable-optimizations
    make -j$(nproc)
    make altinstall
  5. 验证安装

    python3.9 --version

在CentOS上安装Python 3.9:

  1. 更新系统并安装依赖项

    sudo yum update
    sudo yum install -y gcc openssl-devel bzip2-devel libffi-devel zlib-devel readline-devel sqlite-devel
  2. 下载Python 3.9源代码

    wget https://www.python.org/ftp/python/3.9.9/Python-3.9.9.tgz
  3. 解压缩源代码并进入目录

    tar -xf Python-3.9.9.tgz
    cd Python-3.9.9
  4. 配置和安装

    ./configure --enable-optimizations
    make -j$(nproc)
    sudo make altinstall
  5. 验证安装

    python3.9 --version

这些步骤应该在大多数情况下都能在不同的Linux发行版上安装Python 3.9。请注意,部分步骤可能会因为发行版的不同而略有变化,特别是在安装依赖项时。确保您在执行命令之前仔细阅读并理解每个步骤。

安裝pip

    sudo apt install -y python3-venv python3-pip
Python
本站立足于美利堅合衆國,請讀者自覺遵守當地法律!如有違規,本站不承擔任何法律責任! This site is based in the United States of America, readers are requested to abide by local laws! If there are any violations, this site does not bear any legal responsibility! Theme Jasmine by Kent Liao