asdqwe
asdqwe

Reputation: 1

Invoking python passing a path to search for modules to import

How can I achieve something like $ python --search-for-includes=/foo/bar /home/user/x/script.py,where script.py has import something and something.py is in /foo/bar, without editing an environment variable, and without editing script.py.

I tried python -c 'import sys; sys.path.append("/foo/bar")' /home/user/x/script.py, but it did not work.

Upvotes: 0

Views: 72

Answers (1)

falsetru
falsetru

Reputation: 369054

Use PYTHONPATH environment variable in following way:

$ PYTHONPATH=/foo/bar:$PYTHONPATH python /home/user/x/script.py

Upvotes: 1

Related Questions