在从源代码构建 python 3.7.2 时,我做了一些测试和研究,以确定在 Debian 9.8 上安装时到底需要哪些“-dev”包才能成功构建和安装 Python:
如何在 Debian 9.8 上从源代码构建和安装 Python 3.7.x
我特意避免引入比我需要的更大的软件包集合。大集合没问题,但希望顶级列表很小,我想看到顶级列表。
我最终列出了两个必须的项,这些项对于成功完成构建/安装是必需的,另一个是必需的,另外八个是可选的。
我是否可以使用 apt 命令行工具(例如 apt-cache)中提供的信息来获得相同或接近的答案?如果可以,如何获得?
注意:我尝试sudo apt-get build-dep python3.5
了https://devguide.python.org/setup/但这似乎不是最理想的,因为它显示的包列表比我给出的列表要大得多。
$ sudo apt build-dep python3.5
Reading package lists... Done
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
autoconf automake autopoint autotools-dev blt-dev build-essential debhelper dh-autoreconf dh-strip-nondeterminism
diffstat docutils-common dpkg-dev g++ g++-6 gettext intltool-debian libarchive-zip-perl libbluetooth-dev libbz2-dev
libdb-dev libdb5.3-dev libdpkg-perl libexpat1-dev libffi-dev libfile-stripnondeterminism-perl libfontconfig1-dev
libfreetype6-dev libgdbm-dev libice-dev libjs-sphinxdoc libjs-underscore liblzma-dev libmpdec-dev libncursesw5-dev
libpng-dev libpthread-stubs0-dev libreadline-dev libsm-dev libsqlite3-dev libssl-dev libstdc++-6-dev libtinfo-dev
libtool libx11-dev libxau-dev libxcb1-dev libxdmcp-dev libxext-dev libxft-dev libxrender-dev libxss-dev libxt-dev m4
net-tools pkg-config po-debconf python-babel-localedata python3-alabaster python3-babel python3-docutils
python3-imagesize python3-jinja2 python3-pygments python3-roman python3-sphinx python3-tz quilt sharutils
sphinx-common tcl-dev tcl8.6-dev time tk-dev tk8.6-blt2.5 tk8.6-dev x11proto-core-dev x11proto-input-dev
x11proto-kb-dev x11proto-render-dev x11proto-scrnsaver-dev x11proto-xext-dev xorg-sgml-doctools xtrans-dev xvfb
zlib1g-dev
0 upgraded, 85 newly installed, 0 to remove and 1 not upgraded.
Need to get 44.3 MB of archives.
After this operation, 153 MB of additional disk space will be used.
Do you want to continue? [Y/n]
更新:如果我安装在链接的 python 问题中找到的一组开发包,我将获得以下全套内容:
$ sudo apt install zlib1g-dev libffi-dev libssl-dev libbz2-dev libncursesw5-dev libgdbm-dev liblzma-dev libsqlite3-dev tk-dev uuid-dev libreadline-dev
[sudo] password for parallels:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
build-essential bzip2-doc dpkg-dev g++ g++-6 libalgorithm-diff-perl libalgorithm-diff-xs-perl
libalgorithm-merge-perl libdpkg-perl libexpat1-dev libfile-fcntllock-perl libfontconfig1-dev libfreetype6-dev
libice-dev libpng-dev libpng-tools libpthread-stubs0-dev libsm-dev libssl-doc libstdc++-6-dev libtinfo-dev
libx11-dev libx11-doc libxau-dev libxcb1-dev libxdmcp-dev libxext-dev libxft-dev libxrender-dev libxss-dev libxt-dev
pkg-config tcl-dev tcl8.6-dev tk8.6-dev x11proto-core-dev x11proto-input-dev x11proto-kb-dev x11proto-render-dev
x11proto-scrnsaver-dev x11proto-xext-dev xorg-sgml-doctools xtrans-dev
Suggested packages:
debian-keyring g++-multilib g++-6-multilib gcc-6-doc libstdc++6-6-dbg libice-doc liblzma-doc ncurses-doc
readline-doc libsm-doc sqlite3-doc libstdc++-6-doc libxcb-doc libxext-doc libxt-doc tcl-doc tcl8.6-doc tk-doc
tk8.6-doc
The following NEW packages will be installed:
build-essential bzip2-doc dpkg-dev g++ g++-6 libalgorithm-diff-perl libalgorithm-diff-xs-perl
libalgorithm-merge-perl libbz2-dev libdpkg-perl libexpat1-dev libffi-dev libfile-fcntllock-perl libfontconfig1-dev
libfreetype6-dev libgdbm-dev libice-dev liblzma-dev libncursesw5-dev libpng-dev libpng-tools libpthread-stubs0-dev
libreadline-dev libsm-dev libsqlite3-dev libssl-dev libssl-doc libstdc++-6-dev libtinfo-dev libx11-dev libx11-doc
libxau-dev libxcb1-dev libxdmcp-dev libxext-dev libxft-dev libxrender-dev libxss-dev libxt-dev pkg-config tcl-dev
tcl8.6-dev tk-dev tk8.6-dev uuid-dev x11proto-core-dev x11proto-input-dev x11proto-kb-dev x11proto-render-dev
x11proto-scrnsaver-dev x11proto-xext-dev xorg-sgml-doctools xtrans-dev zlib1g-dev
0 upgraded, 54 newly installed, 0 to remove and 0 not upgraded.
Need to get 31.4 MB of archives.
After this operation, 106 MB of additional disk space will be used.
Do you want to continue? [Y/n]
使用该方法时,结果为“新安装 85 台” build-dep
;使用我的自定义列表时,结果为“新安装 54 台”。我该如何缩小这一差距?
答案1
一般来说,apt-get build-dep PKGNAME
将安装从源代码重建该包所需的所有依赖项。
或者,apt-cache
将以各种方式列出软件包依赖项。构建时通常需要-dev
软件包的版本。但是,这不会涵盖所有必需的构建工具(build-essential
等等)。
对于 Python 来说,最简单的方法是阅读文档:
在 Debian、Ubuntu 和其他基于 apt 的系统上,尝试使用 apt 命令获取您正在使用的 Python 的依赖项。
首先,请确保您已在源列表中启用源包。您可以通过将源包的位置(包括 URL、发行版名称和组件名称)添加到 /etc/apt/sources.list 来执行此操作。以 Ubuntu Bionic 为例:
deb-src http://archive.ubuntu.com/ubuntu/ bionic main
对于其他发行版(例如 Debian),请更改 URL 和名称以与特定发行版相对应。
然后你应该更新包索引:
$ sudo apt-get update
现在您可以通过 apt 安装构建依赖项:
$ sudo apt-get build-dep python3.6
如果您的系统没有该软件包,请尝试降低次要版本,直到找到可用的软件包。
对于最小构建来说,它将是apt-get build-dep python3.6-minimal
对于提供的项目configure
(例如 cpython),输出应详细说明正在查找哪些依赖项以及构建所需的依赖项。您可以使用提供的开关禁用所有可选依赖项(无论是否安装)(请参阅./configure --help
)。