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:
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?
ssh://n7@dmai:/opt/itinerator/pyre/bin/python -u /home/n7/.pycharm/pycharm_helpers/pydev/pydevd.py --client '0.0.0.0' --port 41016 --file /home/n7/dm/src/lib/datamap/classify.py pydev debugger: starting Connected to pydev debugger (build 117.663) Traceback (most recent call last): File "/home/n7/.pycharm/pycharm_helpers/pydev/pydevd.py", line 1401, in <module> debugger.run(setup['file'], None, None) File "/home/n7/.pycharm/pycharm_helpers/pydev/pydevd.py", line 1055, in run pydev_imports.execfile(file, globals, locals) #execute the script File "/home/n7/dm/src/lib/datamap/classify.py", 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?
Please sign in to leave a comment.
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 sales@jetbrains.com.
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
import
^
SyntaxError: invalid syntax
Content of the bash script:
#!/bin/bash
# Set system variable to run subscription manager
export PYTHONPATH=/path/to/module/:/path/to/another/module/
export SOME_SYS_VARIABLE=3
# 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/pydev_run_in_console.py ignores $PYTHONPATH :-(
I found evil hack. I added required paths to sys.path in starting script /home/user/.pycharm_helpers/pydev/pydev_run_in_console.py and /home/user/.pycharm_helpers/pydev/pydevd.py.
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.
@... Solution worked for me as well. Thanks.
Actually setting the PYTHONPATH in interpreter setting does not work while like @... said, adding to, for instance, Console env variable, works