在 Linux 中创建独立于系统的最小 Python 占用空间
我的目的是尝试编译这样一个 Linux Python 最小基础,它是完全可移植的,并且独立于系统(意味着它甚至根本不与系统安装的 Python 基础交互)。
它在 Windows 下相对容易完成,除了 Python 二进制文件和由这个可移植的 Python 库加载的最小但自定义的模块集之外什么都没有。
然而,在 Linux 下我也很难达到这个目标,因为从头开始编译 Python 仍然会从系统(例如 /usr/lib/python2.6)加载模块,而不是从它自己的 Lib 子目录加载,这失败了一旦我把这个Python库移到别处就可以找到它。
如果可能的话,有没有一种方法可以将“python”编译为比我编译的发行版更多的基于Linux的发行版可执行的?
编辑:实际上,当我尝试将 python2.6 (或只是 python)移动到已经设置的 Python 库(它在 Windows 下正常工作,但它输出找不到平台无关的库
找不到平台相关库
考虑在 Linux 下将 $PYTHONHOME 设置为
据我所知,这可能与 LIBDIR 设置为 (exec_prefix)/lib/python 有关$(VERSION)
而不是我最近设置的 (exec_prefix)/lib
。
有没有办法定义要读取的文件夹和文件,而不是默认的文件夹和文件? Makefile 正确处理它(make 和 make install 将其放入正确的 lib 文件夹中)。但是当使用farfromhome的print pth
方法时,它仍然倾向于从/home/arnold/Python/lib/python2.6
而不是/home/arnold/加载Python/lib
.
有没有办法强制 python 加载自定义 LIBDIR 路径而不是默认路径?
注意:此安装的文件和文件夹结构与现有的 Linux 或 Windows Python 安装不同
My intention is to try to compile such a Linux Python minimal base, that is totally portable, and system-independent (meaning that it doesn't even interacts with the system-installed Python base at all).
It was done with relative ease under Windows, having nothing but the Python binary files, and a minimal, yet custom set of modules which are being loaded by this portable Python base.
However, it's quite difficult for me to reach this goal under Linux aswell, since compiling Python from scratch will still load the modules from the system (eg. /usr/lib/python2.6) instead from it's own Lib subdirectory, which fails to find it once I move this Python base elsewhere.
If it's possible, is there a way to compile 'python' to be executable for more Linux based distros, than on the one I compiled in?
EDIT: Actually, the problem comes when I try to move the python2.6 (or just python) into the already set up Python base (which is working as it should under Windows, but it outputsCould not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] under Linux instead.
From what I can tell, it might have to do with LIBDIR being set to (exec_prefix)/lib/python$(VERSION)
instead of (exec_prefix)/lib
which I set lately.
Is there a way on defining which folders and files to read from, instead of the default ones? Makefile handles it properly (make and make install places it into the right lib folder). But when using farfromhome's print pth
method, it still tends to load from /home/arnold/Python/lib/python2.6
instead of /home/arnold/Python/lib
.
Is there a way to force python
to load the custom LIBDIR path instead of the default one?
Note: This installation's file and folder structure is different than from the stock Linux or Windows Python installation
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
按照您自己的建议使用
--prefix
是有效的。我使用--prefix=/usr/local
编译了 Python 2.7.1,并运行生成的二进制结果:请注意,没有对
/usr/lib
的单个引用,只是/usr/local/lib
。这是在编译期间或之后没有做任何其他事情的情况下。Using
--prefix
as you yourself suggested works. I compiled Python 2.7.1 with--prefix=/usr/local
, and running the resultant binary results in:Note that there's not a single reference to
/usr/lib
, just/usr/local/lib
. And this is without doing anything else in the compilation or afterwards.