如何从源代码编译 python 并获得干净/最小安装?
如果您遵循简单的配置
-> 制作
->从源代码编译 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
查看 Debian 的
python2.7-minimal
软件包(apt-get source python2.7-minimal
)可能会有所帮助。当有疑问时,总是看看其他人,尤其是专家,正在做什么......来自
debian/rules
那里: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:The
MIN_*
variables are parsed out fromREADME.Debian.in
, which of course doubles as the packageREADME
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.
没有这样的选项 - 保持安装原样是一件好事(也许您可以手动删除测试文件)。 .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 *.
此类选项(如果它们存在于软件本身中)通常可以在
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. Checkconfigure -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.注意 Python 有内置模块,Python 可执行文件,独立的,可以正常工作。您可以删除任何不需要的模块,这取决于您(或其他人)来确定不需要哪些模块。但请注意每个模块的依赖关系。
有些模块是内置的,因此始终存在。要获取内置模块的列表,请转储 sys.builtin_module_names 的内容。
例如,使用独立的 Python 3.4.1 可执行文件,在 Ubuntu 平台上编译:
这说明:
_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:
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.