docker 容器配置python3.12.13

发布时间:2026/6/29 21:16:02
docker 容器配置python3.12.13 docker 容器配置python3.12.13你的容器是Ubuntu 24.04 noble但之前混入了jammy(22.04)源两套系统库版本冲突导致 ncurses、tinfo 依赖卡死所有工具装不上。下面一次性修复。1. 重写纯 24.04 阿里源覆盖错误源cp/etc/apt/sources.list /etc/apt/sources.list.baktee/etc/apt/sources.list-EOF deb http://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse # deb-src http://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse EOF2. 清理损坏包、修复依赖、刷新源aptcleanapt-finstall-yaptautoremove--purge-yaptupdate --fix-missing3. 安装 Python 编译全套依赖24.04 适配24.04 已经移除libncurses5-dev改用libncurses-dev删掉这个包就不会冲突aptinstall-ybuild-essentialwgetlibssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev libffi-dev libncurses-dev执行完这条wget、make、gcc都会正常安装。4. 编译 Python 3.12.13cd/tmpwgethttps://www.python.org/ftp/python/3.12.13/Python-3.12.13.tar.xztar-xfPython-3.12.13.tar.xzcdPython-3.12.13 ./configure --enable-optimizations --with-sslmake-j$(nproc)makealtinstall5. 创建虚拟环境并安装依赖cd/home/pstzwrm-rfvenv /usr/local/bin/python3.12-mvenv venvsourcevenv/bin/activate pipinstall--upgradepip-ihttps://pypi.tuna.tsinghua.edu.cn/simple pipinstall-rrequirements.txt tensorflow-ihttps://pypi.tuna.tsinghua.edu.cn/simple关键注意点Ubuntu24.04(noble) 不存在libncurses5-dev强行安装必报依赖错误替换成libncurses-dev绝对不能同时存在 jammy noble 两种源否则持续版本冲突前面所有command not found都是因为 apt 安装失败工具没装上修复源依赖后即可正常。