How to link virtualenv to PyCharm's env depending on git branch?
I have several branches in the same project that work with a certain virtualenv and another branch with a different virtualenv.
First of all, PyCharm doesn't seem to be able to figure out that I am using a virtualenv other than in the terminal environment, but in other parts of the IDE it just thinks I am using the default packages. One proof of this is when setting up a new configuration to run python manage.py runserver in Django I am getting an error about missing modules. Well, these modules ARE installing in the virtualenv, but not in the default installation, which is not the environment I want to use for this branch.
So how can I apply the virtualenv to the entire environment of the IDE? And how can I switch environments, or between default and virtualenvs depending on the branch (git) I am currently working on?
I tried doing the following:
I set up a new project interpreter selecting c:\python27 as interpreter path as well as Envs\<myvirtualenv>\Lib\site-packages so that the packages used are the virtuaenv ones. I also deselected all interpreter paths concerning libraries from c:\python27, like c:\python27\Lib\site-packages, etc.
Then I created a new configuration to execute python manage.py with the runserver option, and under the environment section I chose the Python interpreter I just set up.
However, when actually running the configuration, it seems that the Python interpreter magically switches back to the previous one, causing it to pull the wrong packages. Why is PyCharm doing this? Why isn't it using the interpreter I am setting it up to use?
Please sign in to leave a comment.