Vagrant and virtualenv
I have a Vagrant box, inside of which there's a virtualenv for a Flask web application. There's a shared folder between the host machine and the virtual machine in which I store the web application files. In PyCharm, I can see that I can set up a virtualenv locally, and I can see that I can set up a remote interpreter using Vagrant, but as far as I can see, there's no way to do both at once. Even if I set up the Vagrant interpreter first then try to create a new virtualenv, it won't let me select the interpreter I've just created.
Note that I'm running PyCharm on macOS and the Vagrant box is Linux, so I can't just re-use the virtualenv locally.
I've tried searching the web and these forums, but nothing seems to cover doing both at once, which is surprising to me because it's not exactly an uncommon scenario.
Please sign in to leave a comment.
Creating remote virtualenv from PyCharm is not supported yet: http://youtrack.jetbrains.com/issue/PY-6002 .
But you can create it on the server manually and add it as a regular remote interpreter - just set the path to python executable file in your virtual environment as Python Interpreter Path for your remote interpreter.
Thanks Anna – I'm actually not all that concerned about creating the virtualenv, more about the runtime behaviour. Normally with a virtualenv you source the virtualenv/bin/activate script. This sets environment variables like $PYTHONHOME, $PATH, and $VIRTUAL_ENV, not to mention the fact that I've got a few Flask and application-specific environment variables set up there as well. Just running the correct Python executable isn't equivalent to running it within the virtualenv.
Does setting the path to the Python executable in PyCharm also set these things up? How would I go about providing additional environment variables like $FLASK_DEBUG and $FLASK_APP?
It's been a few months. Do we have an answer for this?
It's been two week more ;)
Setting the remote interpreter should be enough, as it is when you define a local interpreter from a loval virtualenv.
Additional envs can be set within the launch configurations...
I am having a similar problem. I can set the remote interpreter but the IDE is not able to resolve that the packages are pip installed in a venv on the Vagrant box. My only option seems to be creating a duplicate installation of my Python packages locally. (That fails for separate reasons on a private repo anyway.) I would prefer to use the venv that already exists on the Vagrant box. Setting up the remote interpreter doesn't accomplish this. Perhaps it would work if packages were installed globally on the vagrant box, but that's not support for a virtual environment.