Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pycharm - Configure PYTHONPATH in Remote Interpreter

I have PyCharm 2.7.3 installed on Windows, and I am trying to remotely develop an application on a Linux machine.

So far I can run simple programs, however I'm trying to set my PYTHONPATH and it seems that PyCharm specifically ignores this configuration.

Under my run configuration, I've tried setting PYTHONPATH=/path/to/my/libs, however if I print this environment variable from Python through os.environ, it is ignored. If I set another environment variable, for example ASDF=42, the value is printed as expected - so it's something special with PYTHONPATH.

Under interpreters, I tried adding it under the Paths tab, but this tab only supports Windows paths, so it seems to be local only.

import os

if __name__ == '__main__':
    print os.environ['PYTHONPATH']
    print os.environ

The output of the first line of this program changes based on check boxes in the run config, all with PYTHONPATH=/path/to/my/libs

With Add content roots to PYTHONPATH and Add source roots to PYTHONPATH checked, and PYTHONPATH=/path/to/my/libs, the first line of output is the remote root of my project - but still not my lib directory.

If I uncheck the source roots box, the path remains empty (but the variable is set, to the empty string).

What am I doing wrong?

like image 756
mindvirus Avatar asked Sep 03 '13 22:09

mindvirus


1 Answers

I believe this is a bug in PyCharm, but in the meantime, I've found a workaround.

The heart of the issue is that with a remote interpreter, the Path configure dialog is for the local machine, not the remote machine. So the solution is to set up deployment to the remote machine, and map local folders to path folders on the remote machine.

In the paths tab, add empty windows folders to your project, representing each of the lib directories, then in Tools -> Deployment -> Configuration, map those directories to your lib directories.

ie. if you have a lib in /my/fancy/python/lib, create a folder C:\IdeaProjects\MyProject\my_fancy_python_lib, and then create a mapping to /my/fancy/python/lib in the deployment configuration.

Hacks, but it works.

Someone filed a bug report for it here (I posted my answer there too): http://youtrack.jetbrains.com/issue/PY-10739

like image 103
mindvirus Avatar answered Oct 30 '22 06:10

mindvirus