为特定的 Python 版本安装 Python 包

为特定的 Python 版本安装 Python 包

我了解到在 Ubuntu 14.04 中,您可以访问 python 2.7.6 和 python 3.4.0。通过命令行获取 python 包时,如何确保安装的是适用于 python 2.7.6 而不是适用于 python 3.4.0 的包?

答案1

用于apt-file查找包名称。例如,如果您想安装正确版本的 reportlab,请使用:

apt-file -l search reportlab

在我的系统上,这会产生:

gambas3-gb-report
python-mvpa2
python-pdfrw
python-pisa
python-renderpm
python-renderpm-dbg
python-reportlab
python-reportlab-accel
python-reportlab-accel-dbg
python-reportlab-doc
python3-renderpm
python3-renderpm-dbg
python3-reportlab
python3-reportlab-accel
python3-reportlab-accel-dbg

可以假设软件包 python-reportlab 是 2.7 版本,软件包 python3-reportlab 是 python 3.x 版本。但是,如果您想进一步检查,可以使用dpkg -L python-reportlab— 这将列出软件包内容,您将看到文件位于 中/usr/lib/python2.7

不幸的是,dpkg -L它只适用于已安装的软件包,因此如果你想在安装软件包之前检查它,则必须使用Ubuntu 软件包 Web 界面. 一旦你打开包裹详情页面您可以点击文件列表并找出文件是否在/usr/lib/python2.7或中/usr/lib/python3

相关内容