温馨提示×

ubuntu装python慢为何

小樊
35
2026-10-04 11:03:44
栏目: 编程语言

在 Ubuntu 上装 Python“慢”,通常不是 Python 本身的问题,而是环境、网络或安装方式导致的。下面按常见原因给你梳理一下:


一、用 apt 安装慢(最常见)

1️⃣ 软件源在国外(官方源)

Ubuntu 默认源是 archive.ubuntu.com,国内访问很慢。

✅ 解决:

sudo sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list
sudo apt update

或用清华、中科大源。


2️⃣ apt update 本身慢

更新索引时要拉很多包信息。

✅ 可只装 Python:

sudo apt install -y python3

二、用 pyenv / 源码编译慢(非常常见)

3️⃣ 从源码编译 Python

pyenv install 3.11 会:下载 → 编译 → 安装,特别慢。

原因:

  • 编译依赖多(gcc、ssl、zlib)
  • CPU 性能低(云服务器 / 虚拟机)

✅ 加速方法:

sudo apt install -y build-essential libssl-dev zlib1g-dev
pyenv install 3.11.6

或用预编译版本:

pyenv install 3.11.6 --list

三、pip 安装慢(不是装 Python 慢,是装包慢)

4️⃣ pip 默认连 PyPI 官网

国内非常慢。

✅ 换源:

pip3 install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple

或永久配置:

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

四、系统太老 / 架构问题

5️⃣ Ubuntu 太老

老系统软件源少,依赖难解决。

✅ 建议:

  • Ubuntu 20.04+
  • 或用 deadsnakes PPA:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install python3.11

五、你是不是“装 Python”其实是在等别的?

很多人说“装 Python 慢”,其实是:

  • 装 anaconda(几个 G,当然慢)
  • 装 docker 镜像
  • 装 ros / tf 等依赖

快速判断你属于哪种

你可以告诉我:

  1. Ubuntu 版本(lsb_release -a)
  2. 用的什么方式装(apt / pyenv / 源码 / anaconda)
  3. 卡在哪一步(下载 / 编译 / 配置)

我可以直接给你一条最快的安装命令。

0 踩