可以在 Ubuntu 无网络(离线)环境下安装 Python,只是不能像平时那样直接用 apt 从网上拉包,需要用离线方式。常见几种做法:
如果你有 Ubuntu 的系统安装 ISO 或光盘:
sudo mount -o loop ubuntu.iso /mnt
sudo apt-cdrom -m -d=/mnt add
sudo apt update
sudo apt install python3
✅ 适合:服务器、内网机、无外网环境
.deb 包,拷到机器上装(最常用)在有网的机器(同版本 Ubuntu)上:
apt download python3 python3-minimal libpython3*
或
sudo apt-get install --download-only python3
包在:
/var/cache/apt/archives/
拷贝到离线机器后:
sudo dpkg -i *.deb
sudo apt-get install -f
✅ 适合:生产环境、公司内网
无网但你有 Python 源码包(.tar.xz):
tar -xf Python-3.11.tar.xz
cd Python-3.11
./configure --prefix=/usr/local/python3
make
sudo make install
⚠ 注意:
gcc、make、libssl-dev 等✅ 适合:需要特定 Python 版本
在有网机器下载:
Miniconda3-latest-Linux-x86_64.sh
离线机器直接:
bash Miniconda3-latest-Linux-x86_64.sh
✅ 不依赖系统 Python
✅ 非常适合无网环境
其实 Ubuntu 基本都预装了 Python3:
python3 --version
如果没有,再考虑上面的方式。
| 场景 | 推荐方式 |
|---|---|
| 完全无网 | ISO / deb 离线包 |
| 内网服务器 | dpkg 离线安装 |
| 特定版本 | 源码编译 |
| 数据/AI | Miniconda 离线 |
如果你愿意,可以告诉我:
我可以给你精确命令。