温馨提示×

debian怎么安装python

小樊
39
2026-10-11 01:03:34
栏目: 编程语言

在 Debian 系统上安装 Python 有多种方式,下面按最常见、最推荐的方法给你说明。


一、使用 apt 安装(推荐,最简单)

1. 更新软件源

sudo apt update

2. 安装 Python(以 Python 3 为例)

sudo apt install python3

3. 安装 pip(Python 包管理器)

sudo apt install python3-pip

4. 验证安装

python3 --version
pip3 --version

二、安装指定版本的 Python(如 Python 3.11)

Debian 稳定版自带的 Python 版本可能较旧,如果你需要新版本:

方法 1:使用 deadsnakes 类似源(Debian 不常用)

Debian 一般不推荐加 Ubuntu 的 PPA。

方法 2:从源码编译(最灵活)

sudo apt install -y build-essential libssl-dev zlib1g-dev \
libncurses5-dev libffi-dev libsqlite3-dev wget
wget https://www.python.org/ftp/python/3.11.6/Python-3.11.6.tgz
tar -xzf Python-3.11.6.tgz
cd Python-3.11.6
./configure --enable-optimizations
make -j$(nproc)
sudo make altinstall

⚠️ 用 altinstall 避免覆盖系统 Python

验证:

python3.11 --version

三、使用 pyenv 管理多版本(开发推荐)

curl https://pyenv.run | bash

按提示配置 ~/.bashrc 或 ~/.zshrc 后:

pyenv install 3.11.6
pyenv global 3.11.6

四、注意事项(很重要)

❌ 不要卸载系统自带的 python3(apt、系统工具依赖它)
✅ 使用 python3 / pip3 而不是 python


如果你是:

  • 服务器环境
  • 桌面版 Debian
  • 想装 Python 2(不推荐)

可以告诉我,我可以给你更具体的步骤。

0 踩