Using a virtual environment on a remote machine


Running Pycharm on Mac OS X. Developing on a Raspberry PI. I can create and use a remote interpreter on the Pi over SSH. I would like to use a remote environment on the Pi (venv-3.4 with Python 3.4). How do I create a remote interpreter in Pycharm, that uses a remote environment?




Comment actions Permalink

Hello Martin,
Creating remote virtualenv from PyCharm is not supported yet: But you can just create it on the server manually and add it as a regular remote interpreter.

Comment actions Permalink

How do you activate the venv for PyCharm remote execution once it is created? 

PyCharm 2017.3.2 (Professional Edition)
Build #PY-173.4127.16
SSH Remote Run v0.1 confirmed active

I don't see any options for selection and activation of remote venv on either

  • Build, Execution, Deployment > Deployment
  • Build, Execution, Deployment > Deployment > Options

Setting the Python interpreter path in Project: name-of-project > Project Interpreter does not set up the environment variables with activate. As a result, it seems you can only get the Python binary that resides at a path that happens to be in a venv, but would not provide the paths required to use the contents of the venv. Not to mention that this dialog ends up being completely non-functional, giving "Project level deployment servers are not currently supported. Please create one using any of the two links above." Neither of the links have any apparent action.

See also:

Comment actions Permalink

Hi. I found a solution which works (implements remote virtualenv interpreter in PyCharm!)

1. Create script (e.g. /usr/bin/python36fortytwo)

source /home/pavel/.virtualenvs/fortytwo/bin/activate
# now we call python which should be python from our virtualenv
python "$@"

2. chmod +x /usr/bin/python36fortytwo

3. Create remote interpreter specifying /usr/bin/python36fortytwo as command

You can use it in Run configuration and list/deploy packages

Run the project and you see it running:


ssh://root@ -u /opt/dev/fortytwo/ runserver
Performing system checks...

System check identified no issues (0 silenced).

You have 15 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python migrate' to apply them.

September 06, 2018 - 19:53:00
Django version 2.1.1, using settings 'fortytwo.settings'
Starting development server at
Quit the server with CONTROL-C.

Comment actions Permalink

Perhaps I am missing something but what prevents you from selecting /home/pavel/.virtualenvs/fortytwo/bin/python as a Python interpreter path? PyCharm will correctly resolve venv specific packages.

Comment actions Permalink

I am new to python and virtualenv, so if I am not sure what is done in background, I do it the way which leaves less possibility for errors :)

e.g. I compared environment variables before ant after activating "fortytwo" virtualenv, so two things get set in environment


making virtualenv's /bin directory first on PATH makes it be the first to search for "pip" for example

Maybe in PyCharm context this doesn't matter (e.g. it calls "python -m pip" and not just "pip"), maybe somewhere it does, I don't know for sure, but this way makes sure it will work same as it would for user on that machine


Of course the better way is to put file in every virtualenv directory with content:


source bin/activate
python "$@"

and the give it to PyCharm as /home/pavel/.virtualenvs/fortytwo/

so it

1. doesn't live in OS bin directories
2. doesn't have virtualenv/project specific content in it.


Comment actions Permalink

@Pavel, @Anna

No as far as I can see it *does not work*. Of course I can select the python executable in the remote virtualenv, but then all the packages that are *only* installed in the virtualenv will be missing.

Please prove me wrong!

Comment actions Permalink

@Stefan Here is my example, pytest is installed only for the virtual environment:

Comment actions Permalink

That seems to work fine.  Here are my steps:


sudo apt-get install --upgrade python3-dev python3-venv
python3 -m venv MYENV
MYENV/bin/pip install -U pip setuptools wheel
source MYENV/bin/activate
pip3 install -U smbus2



Comment actions Permalink

I had the same issue and solved it also with selecting the python interpreter from the virtual environment. In my case


I faced also the problem to run a script to set some env variables for qt5. With the solution from Pavel it's now possible for me to use X11 features. Thank you! 

Comment actions Permalink

On Cloud (EC2 instance e.g.,)

$ source activate tensorflow2dot7

(tensorflow2dot7) ubuntu@ip-172-31-88-172:/usr/bin$ python

Python 2.7.16 |Anaconda, Inc.| (default, Mar 14 2019, 21:00:58) 

>>> import sys

>>> print(sys.executable)



Then use this "/home/ubuntu/anaconda3/envs/tensorflow2dot7/bin/python" in Pycharm Interpreter



Comment actions Permalink

[Connecting to Ubuntu 18.04 with Python 3.6 from PyCharm Professional 2019.2]

Sadly, pointing the interpreter to the python executable in the venv does not solve the issue of missing modules, I still have to use @Pavel Paidem's solution:


source <path-to-venv>/bin/activate
python "$@"

Setting this file as interpreter works without issue, but is not the desired way of achieving it, as some people have pointed out that it should work natively.

Comment actions Permalink


Please feel free to vote for and leave comments.

Comment actions Permalink

@Sergey Karpov

Any other workarounds for this issue?




Please sign in to leave a comment.