0

I'd like to alter my $PATH only in a Python virtual environment. Is it possible to have the $PATH change when I activate a virtual environment?

3
  • Why would you want to do this? Commented Mar 5, 2015 at 16:35
  • I need access to a binary while in this environment, and would prefer not to permanently alter $PATH to get it. Commented Mar 5, 2015 at 17:21
  • @no_name - i do this to create a test environment. Activating the test environment starts by activating the virtualenv and then adding to the environment (and even mapping drives and running other programs). One stop shopping. Commented Mar 6, 2015 at 16:20

2 Answers 2

1

You can write an activation script that sources virtualenv's activate (on linux, or calls the bat file on windows) and then updates PATH, PYTHONPATH and other environment variables. Use the virtualenv bootstrap hooks to install the script when the virtualenv is created and call it instead of activate.

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

Comments

0

Depending on what operating system you are using you could edit the activate file and set an environment variable there. For example, a Windows virtualenv folder has a sub-folder called Scripts. Inside scripts is the activate.bat file. Edit activate.bat and alter the path variable. One thing to consider though, is you might want to save the original path variable in another temporary environment variable and restore from that temporary environment variable in the deactivate.bat file.

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.