Question

I have a set of scripts, that are executed using a specific python installation (set with a first line #!). There are a few different python installations on the network, and different groups have their own set-ups and workflows. Some groups have instructed people to modify their PYTHONPATH in their shell logins, in order to run their tools. If someone has modified their PYTHONPATH, and it a directory in it contains versions of a package that is incompatible with a script of mine, is there a recommended way to either:

  • ignore a user's PYTHONPATH env variable, or
  • make sure a specific site-packages directory is searched first?

Basically, people have modified their PYTHONPATHs, and need also to run my scripts. I'd like to make them universally available on the system, without people having to mess with their set-ups.

Thanks for the help.

Was it helpful?

Solution

You can do this at the beginning of your script:

import sys
sys.path.insert(0, 'specific/site-packages')

It is equivalent to specific/site-packages being first in PYTHONPATH.

OTHER TIPS

I would suggest either to install the modules framework and write an appropriate module or to create a custom file (say .pysource) that users should source before running your scripts.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top