Pycharm-在远程解释器中配置PYTHONPATH [英] Pycharm - Configure PYTHONPATH in Remote Interpreter

查看:244
本文介绍了Pycharm-在远程解释器中配置PYTHONPATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows上安装了PyCharm 2.7.3,我正尝试在Linux计算机上远程开发应用程序。

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

到目前为止,我可以运行简单的程序,但是我正在尝试设置我的PYTHONPATH,似乎PyCharm特别忽略了此配置。

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

在我的运行配置下,我尝试设置 PYTHONPATH = / path / to / my / libs ,但是,如果我通过 os.environ 从Python打印此环境变量,它将被忽略。如果我设置了另一个环境变量,例如 ASDF = 42 ,则将按预期方式打印该值-因此PYTHONPATH有点特殊。

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.

在解释器下,我尝试将其添加到路径选项卡下,但是此选项卡仅支持Windows路径,因此它似乎仅是本地路径。

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

该程序第一行的输出根据运行配置中的复选框而变化,所有这些均 PYTHONPATH = / path / to / my / libs

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

使用将内容根添加到PYTHONPATH 将源根添加到PYTHONPATH 中,然后 PYTHONPATH = / path / to / my / libs ,输出的第一行是项目的远程根目录-但仍然不是我的lib目录。

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.

如果我取消选中源根目录框,则路径将保持空白(但变量设置为空stri ng)。

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

我在做什么错了?

推荐答案

我相信这是PyCharm中的错误,但与此同时,我已经找到了解决方法。

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

问题的核心是使用远程解释器,Path配置对话框用于本地计算机,而不是远程计算机。因此,解决方案是设置到远程计算机的部署,并将本地文件夹映射到远程计算机上的路径文件夹。

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.

在路径选项卡中,将空Windows文件夹添加到您的项目,代表每个lib目录,然后在工具->部署->配置中,将这些目录映射到您的lib目录。

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。如果您在 / my / fancy / python / lib 中有一个lib,请创建一个文件夹 C:\IdeaProjects\MyProject\my_fancy_python_lib ,然后在部署配置中创建到 / my / fancy / python / lib 的映射。

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.

没问题,但是可以。

有人为此在这里提交了错误报告(我也把答案贴在了这里): http://youtrack.jetbrains.com/issue/PY-10739

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

这篇关于Pycharm-在远程解释器中配置PYTHONPATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆