如何从源代码编译 python 并获得干净/最小安装?

发布于 2024-10-19 12:33:38 字数 395 浏览 1 评论 0原文

如果您遵循简单的配置 -> 制作 ->从源代码编译 python 的 make install 过程中,您最终会得到一个非常大的安装,其中包含大量对于功能性 python 环境来说不是必需的文件。例如:所有 .py 文件都保留在安装中(不仅仅是 .pyc.pyo 文件),所有单元测试都进行对于 lib 文件夹中的每个库,都包含手册页等。

是否有一种固定的方法(make 选项?)来在安装过程中忽略或删除“不必要的”文件,以便您留下一个简约但完全的文件函数式的,python 发行版?

如果没有预先制定的程序,可以删除哪些文件,同时确保安装仍然可以在安装的计算机上运行?

If you follow the simple configure -> make -> make install process for compiling python from source code, you end up with a very large install that includes a whole lot of files that are not necessary for a functional python environment. eg: All .py files are left in the installation (not just the .pyc or .pyo files), all the unit tests are carried over for each library in the lib folders, man pages are included, etc.

Is there a canned way (make option?) to ignore or strip out the 'unnecessary' files during the install process so you are left with a minimalist, but fully functional, python distribution?

If no pre-made procedure, what files can be stripped out, while being certain that the installation will still work on the machine it was installed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浮云落日 2024-10-26 12:33:38

查看 Debian 的 python2.7-minimal 软件包(apt-get source python2.7-minimal)可能会有所帮助。当有疑问时,总是看看其他人,尤其是专家,正在做什么......

来自 debian/rules 那里:

: # Move the binary and the minimal libraries into $(p_min).
dh_installdirs -p$(p_min) \
        etc/$(PVER) \
        usr/bin \
        usr/include/$(PVER) \
        usr/share/man/man1 \
        $(scriptdir)/lib-dynload \
        $(scriptdir)/config
DH_COMPAT=2 dh_movefiles -p$(p_min) --sourcedir=$(d) \
        usr/bin/python$(VER) \
        usr/share/man/man1/python$(VER).1 \
        $(foreach i,$(MIN_MODS),$(scriptdir)/$(i).py) \
        $(foreach i,$(MIN_PACKAGES),$(scriptdir)/$(i)) \
        $(foreach i,$(MIN_ENCODINGS),$(scriptdir)/$(i)) \
        $(scriptdir)/config/Makefile \
        usr/include/$(PVER)/pyconfig.h \
        $(scriptdir)/site.py

MIN_* 变量是从 解析出来的>README.Debian.in,当然它也兼作 README 包,但也因此成为包含哪些模块的权威。

有趣的东西,我以前从未看过这个。至于你的问题,答案似乎是否定的,Python 中并没有包含真正的最小目标,但也许你可以采用与 Debian 相同的方法来实现你的目标。

It may be instructive to look at Debian's python2.7-minimal package (apt-get source python2.7-minimal). When in doubt, always look to see what others, especially the experts, are doing...

From debian/rules there:

: # Move the binary and the minimal libraries into $(p_min).
dh_installdirs -p$(p_min) \
        etc/$(PVER) \
        usr/bin \
        usr/include/$(PVER) \
        usr/share/man/man1 \
        $(scriptdir)/lib-dynload \
        $(scriptdir)/config
DH_COMPAT=2 dh_movefiles -p$(p_min) --sourcedir=$(d) \
        usr/bin/python$(VER) \
        usr/share/man/man1/python$(VER).1 \
        $(foreach i,$(MIN_MODS),$(scriptdir)/$(i).py) \
        $(foreach i,$(MIN_PACKAGES),$(scriptdir)/$(i)) \
        $(foreach i,$(MIN_ENCODINGS),$(scriptdir)/$(i)) \
        $(scriptdir)/config/Makefile \
        usr/include/$(PVER)/pyconfig.h \
        $(scriptdir)/site.py

The MIN_* variables are parsed out from README.Debian.in, which of course doubles as the package README but also thus becomes the authority on which modules to include.

Interesting stuff, I'd never looked at this before now. As for your question, the answer does seem that no, there isn't really a minimal target included in Python, but perhaps you could take the same approach Debian does to achieve your aims.

甜是你 2024-10-26 12:33:38

没有这样的选项 - 保持安装原样是一件好事(也许您可以手动删除测试文件)。 .py 文件可以方便地进行调试。除此之外:您确实希望保持完整安装不变。处理我们在各种 Linux 发行版上看到的精简 Python 安装通常是一件痛苦的事情。*

There is no such option - and it is a good thing keeping the installation as it is (perhaps you can chop of the test files manually). The .py files are handy for debugging. Apart from that: you really want to keep the full installation as it is. Dealing with stripped down Python installations as we see it on various Linux distributions is often a pain in the *.

阳光下的泡沫是彩色的 2024-10-26 12:33:38

此类选项(如果它们存在于软件本身中)通常可以在 configure 脚本中找到。检查configure -h

或者,如果存在同名的 .pyc 文件,您可以尝试删除 .py 文件。您还可以删除 .pyo 文件。删除 .py.pyo 文件将在 /usr/local/lib/python2.7 下节省 72396 kB(大约 47%)我的Python 2.7.3安装。

Such options (if they exist in the software itself) are usually found in the configure script. Check configure -h.

Alternatively, you could try removing .py files if an identically named .pyc file exists. You can also remove the .pyo files. Removing .py and .pyo files would save 72396 kB under /usr/local/lib/python2.7 (that's around 47%) on my Python 2.7.3 installation.

一腔孤↑勇 2024-10-26 12:33:38

注意 Python 有内置模块,Python 可执行文件,独立的,可以正常工作。您可以删除任何不需要的模块,这取决于您(或其他人)来确定不需要哪些模块。但请注意每个模块的依赖关系。

有些模块是内置的,因此始终存在。要获取内置模块的列表,请转储 sys.builtin_module_names 的内容

例如,使用独立的 Python 3.4.1 可执行文件,在 Ubuntu 平台上编译:

>>> import sys
>>> for m in sys.builtin_module_names: print(m)

这说明:

  • _ast
  • _codecs
  • _collections
  • _functools
  • _imp
  • _io
  • _locale
  • _operator
  • _sre
  • _stat
  • _string
  • _symtable
  • _thread
  • _tracemalloc
  • _warnings
  • _weakref
  • atexit
  • 内置函数
  • errno
  • faulthandler
  • gc
  • itertools
  • marshal
  • posix
  • 密码
  • 信号
  • sys
  • xxsubtype
  • zipimport code>

有私有模块,同时还有 13 个公共模块。所有内容均内置于 Python 可执行文件中,独立。

如前所述,您可以删除任何 *.pyc*.pyo 文件,要使模块正常工作,所有必需的就是 *.py 文件。

Note Python has built‑in modules, the Python executable, standalone, will work fine. You may remove any unneeded modules, it's just up to you (or someone else) to determine which ones won't be required. Be aware of each module dependencies though.

Some modules are built‑in and so always there. To get the list of built‑in modules, dump the content of sys.builtin_module_names.

Ex, with a standalone Python 3.4.1 executable, compiled on an Ubuntu platform:

>>> import sys
>>> for m in sys.builtin_module_names: print(m)

This tells:

  • _ast
  • _codecs
  • _collections
  • _functools
  • _imp
  • _io
  • _locale
  • _operator
  • _sre
  • _stat
  • _string
  • _symtable
  • _thread
  • _tracemalloc
  • _warnings
  • _weakref
  • atexit
  • builtins
  • errno
  • faulthandler
  • gc
  • itertools
  • marshal
  • posix
  • pwd
  • signal
  • sys
  • xxsubtype
  • zipimport

There are private modules, while still 13 public modules. All is built in the Python executable, standalone.

As already mentioned, you can remove any *.pyc and *.pyo files, as for a module to work, all is required, is the *.py files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文