开发者

Having a different LIBDIR path for Python in Linux

I would like to change the way on Python 2.7 under Linux would load its modules/libraries from. I have tried to change it from the Configure file. Before that, it was like:

BINLIBDEST=     $(LIBDIR)/python$(VERSION)
LIBDEST=        $(SCRIPTDIR)/python$(VERSION)
INCLUDEPY=      $(INCLUDEDIR)/python$(VERSION)
CONFINCLUDEPY=  $(CONFINCLUDEDIR)/python$(VERSION)
LIBP=           $(LIBDIR)/python$(VERSION)

And I attempted to change it into this:

BINLIBDEST=     $(LIBDIR)
LIBDEST=        $(SCRIPTDIR)
INCLUDEPY=      $(INCLUDEDIR)
CONFINCLUDEPY=  $(CONFINCLUDEDIR)
LIBP=           $(LIBDIR)

Mainly removing python%(VERSION) from the pathname, so that instead of lib/python27, it would simply load its modules from only lib folder. However, even if initiating make and make install works with the开发者_运维知识库 changes, the python or python27 Python binary file does not loads the modules from the new path. It falls back with this output:

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
'import site' failed; use -v for traceback

Is there a way on forcing the Python binary itself (if must) to load up the modules from a new path set by me, instead of the default one as "$(LIBDIR)/python$(VERSION)"?


You'll have to do a few changes to python source and recompile, but I'm going to assume that is okay, since this is a pretty non-standard thing to do.

Look at the file Modules/getpath.c. The steps python performs to determine the libdir is detailed in the comments in the beginning of the file. You can have a look at the svn repo here. I think you'll want to look at how this define is used:

#define PYTHONPATH PREFIX "/lib/python" VERSION ":" \
          EXEC_PREFIX "/lib/python" VERSION "/lib-dynload"

I don't think it will be as easy as just changing it to [...] PREFIX "/lib/:" [...], but it will be something along those lines.


Are you trying to accomplish something that virtualenv doesn't do?

It seems to meet your requirement:

"...the main idea was not to work with the system-wide Python, but to have a separate, more of a portable version of Python to have its own libraries and modules.."


I'd like to thank carlpett: I was able to set python search path at runtime: changed from lib/ to lib64/ while building Python 2.7.10 in x86_64-my_distro-gnu-linux using gcc 5.1 by modifying Modules/getpath.c.

For the record, I tried --libdir at configure time (works for the shared library but not for python modules install paths), modifying Makefile, modifying pyconfig.h, tweaking $PYTHONPATH, $PYTHONHOME, nothing worked.

Just a detail, but the make install does not place correctly the libraries, so you have to do a little cp -af and mv by yourself.

THANK YOU CARLPETT!!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜