1

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.

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.