I have a system python installation and a personal python installation in my home directory. My personal python comes in ahead in my $PATH and I usually run that. But the system python installation has some modules that I want to use with my personal python installation.
So, basically, I want to append the sys.path of the system python installation to the sys.path of the personal python installation.
I read up on the docs and source of site module and saw that I could use the sitecustomize or usercustomize modules to do this. But where I am stuck is how do I get the sys.path of the system python to be appended to the personal python’s sys.path.
The gensitepackages function in the site modules seems to calculate the paths to be added to sys.path but it is using the PREFIXES global variable instead of taking it as an argument, so for all I know, I can’t use it. Adding system python’s prefixes to PREFIXES is also not an option as by the time the customize module(s) are loaded, the PREFIXES is already used to build the path.
Any ideas on how to go about this?
Also, I’m not sure if I should ask this on askubuntu/unix&linux. Comments?
Edit: Guess I wasn’t clear on this part. I want the system python’s path to be appended so that when I try to use modules that are not present in my personal python, it will automatically fallback to the system python’s modules.
Either set the PYTHONPATH environment variable or, in your personal Python installation’s site-packages directory, add one or more path configuration files (.pth files) that point to the directories you want to add from the system Python installation.
UPDATE: In general, it’s not a good idea to mix modules from different Python instances. For instance, there could be differences in the configure parameters used to build the two Python that could produce incompatibilities in C extension modules built for the existing system Python but used with your personal Python. But, if you really want to go down this path, you could manipulate the path with .pth files or modify the
sitemodule. Or what might be a more-straightforward and easier-to-manage approach is to usevirtualenvto create a private virtual environment using the system Python but then replace the interpreter in the environment; see, for example, the sectionUsing Virtualenv without bin/python.