0

Is there a way to modify PYTHONPATH automatically whenever I cd into a directory.

I usually have multiple projects on my workstation, and whenever I am in one of those directories, I want that projects' src/ to override other src directories in PYTHONPATH.

2
  • 1
    Linux, Windows, or something else? Commented Nov 2, 2013 at 2:41
  • 4
    Check out python virtualenv and virtualenv-wrapper. It allows you to isolate your python work spaces to avoid collisions on projects. docs.python-guide.org/en/latest/dev/virtualenvs Commented Nov 2, 2013 at 2:43

1 Answer 1

2

Have you tried adding './src' to the PYTHONPATH ahead of the other paths that you want to "override"? That ought to work. (Haven't tried it with Python, but most "path" lists allow relative paths to be used.)

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

1 Comment

That's clever... but be careful not to do os.chdir() in your scripts.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.