hawk_sf
hawk_sf

Reputation: 55

Execute script ignoring user's PYTHONPATH

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:

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.

Upvotes: 1

Views: 486

Answers (2)

dmg
dmg

Reputation: 7716

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.

Upvotes: 0

Pavel Anossov
Pavel Anossov

Reputation: 62948

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.

Upvotes: 3

Related Questions