Pycharm - setting PYTHONPATH in the remote interpreter

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

While I can run simple programs, however, I'm trying to install PYTHONPATH, and it seems that PyCharm specifically ignores this configuration.

In my startup configuration, I tried setting PYTHONPATH=/path/to/my/libs , however, if I print this environment variable from Python via os.environ , it will be ignored. If I set another environment variable, for example ASDF=42 , the value will be printed as expected, so this is something special with PYTHONPATH.

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

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

The output of the first line of this program is changed based on the flags in the startup configuration, all with PYTHONPATH=/path/to/my/libs

When checking Add content roots to PYTHONPATH and Add source roots to PYTHONPATH and PYTHONPATH=/path/to/my/libs first line of output is the remote root of my project, but still not the directory of my library.

If I uncheck the root source, the path will remain empty (but the variable is set to an empty string).

What am I doing wrong?

+4
source share
1 answer

I believe this is a bug in PyCharm, but at the same time I found a workaround.

The heart of the problem is that using the remote interpreter, the path settings dialog is for the local computer, not for the remote machine. Thus, the solution is to configure the deployment to the remote machine and map the local folders to the path folders on the remote machine.

On the Paths tab, add empty Windows folders to the project that represent each of the lib directories, then in Tools → Deployment → Configuration, map these directories to your lib directories.

i.e. if you have lib in /my/fancy/python/lib , create the 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 here (I also posted my answer there): http://youtrack.jetbrains.com/issue/PY-10739

+2
source

Source: https://habr.com/ru/post/1500397/


All Articles