PyCharm remote debugging doesn't respect PYTHONPATH settings

I'm having an issue with debugging a remote script. When starting the debugger, the debugger stops with an ImportError, because it can't find the modules imported by the script. Here's the traceback shown in the debugger:

ssh://n7@dmai:/opt/itinerator/pyre/bin/python -u /home/n7/.pycharm/pycharm_helpers/pydev/ --client '' --port 41016 --file /home/n7/dm/src/lib/datamap/
pydev debugger: starting
Connected to pydev debugger (build 117.663)
Traceback (most recent call last):
  File "/home/n7/.pycharm/pycharm_helpers/pydev/", line 1401, in <module>['file'], None, None)
  File "/home/n7/.pycharm/pycharm_helpers/pydev/", line 1055, in run
    pydev_imports.execfile(file, globals, locals) #execute the script
  File "/home/n7/dm/src/lib/datamap/", line 12, in <module>
    from common.pyutils import log_warn, log_debug
ImportError: No module named common.pyutils

Checking sys.path while the script is running shows that it indeed does not have the correct paths loaded. My profile on the remote server has a custom .bashrc that augments the PYTHONPATH with the correct paths - Pycharm obviously doesn't respect that. Shouldn't be a problem, though, because the Configuration settings for the remote interpreter that I set up have an Environment Variables section... so I just added the correct PYTHONPATH variable there. However, this is apparently being ignored, because it has no effect.

This problem means I can't debug remote scripts. What am I missing? How do I get the remote script to run with the correct PYTHONPATH?
Unfortunately we found out that there is no portable way to pass environment variables over an SSH connection, so we are unable to apply the PYTHONPATH settings in the run configuration. You need to configure your remote environment in such a way that it doesn't rely on an externally defined PYTHONPATH environment variable.
Are you serious? Supporting PYTHONPATH is one of the most basic things an environment needs to have, because of the way the interpreter imports other modules. This is very unfortunate. Remote debugging is the prime reason my company paid for a corporate license. I will be reviewing this decision with my team and we may need a refund if there is no workaround for this.
Absolutely. The Python ecosystem provides a wide array of tools (virtualenv, pip, buildout etc.) that allow you to package your application in a way that declares dependencies on other modules explicitly, and does not rely on a globally defined PYTHONPATH.

The easiest workaround that you can use without repackaging your application is to create a shell script that defines the PYTHONPATH environment variable and then runs the actual Python interpreter, and to specify that script as the remote interpreter that PyCharm runs.

In case you will need a refund on your purchase, please contact
Hmm, that is not a bad idea at all. I'll try out the shell script workaround. And yes, we are looking into using virtualenv to control our python environments, but we aren't quite there yet... Thanks for the tips.

I tried to use the trick with bash script. It works, when I run python script at remote machine, BUT it doesn't work, when I try to do debugging of a python code. Debug attempt is terminated with following error:

Error running remote_machine
Can't run remote python interpreter: Couldn't obtain remote socket from output , stderr   File "<string>", line 1
SyntaxError: invalid syntax

Content of the bash script:


# Set system variable to run subscription manager
export PYTHONPATH=/path/to/module/:/path/to/another/module/

# Run python with arguments
/usr/bin/python $@

I have to say that the ability to do remote debugging and setting of PYTHONPATH is cruical for me!

Please, offer some reliable solution!


I have to also note that setting PYTHONPATH (using export PYTHONPATH) in .bashrc or .bash_profile doesn't work too. It seems that /home/user/.pycharm_helpers/pydev/ ignores $PYTHONPATH :-(


I found evil hack. I added required paths to sys.path in starting script /home/user/.pycharm_helpers/pydev/ and /home/user/.pycharm_helpers/pydev/


Jhindek, I have the same problem can you please elaborate on your solution on how to remotely debug a script that is missing a module?


Adding PYTHONPATH as an additional environment variable in the run/debug settings worked for me and a remote interpreter.


Hanan Shteingart Solution worked for me as well. Thanks.


Actually setting the PYTHONPATH in interpreter setting does not work while like Hanan Shteingart said, adding to, for instance, Console env variable, works


Please sign in to leave a comment.