Creating a system-independent minimal Python footprint in Linux
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 outputs
Could not find platform independent libraries开发者_JAVA百科 <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
Using --prefix
as you yourself suggested works. I compiled Python 2.7.1 with --prefix=/usr/local
, and running the resultant binary results in:
Python 2.7.1 (r271:86832, Jan 31 2011, 11:06:01)
[GCC 4.5.1 20100924 (Red Hat 4.5.1-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> for pth in sys.path:
... print pth
...
/usr/local/lib/python27.zip
/usr/local/lib/python2.7
/usr/local/lib/python2.7/plat-linux2
/usr/local/lib/python2.7/lib-tk
/usr/local/lib/python2.7/lib-old
/usr/local/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/site-packages
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.
精彩评论