简体   繁体   English

在子进程中的其他Python解释器上运行的Pycharms调试器

[英]Pycharms debugger running on a different Python interpreter in subprocess

I have a PyCharms python project configured to run on a virtual env (Python 2.7.9). 我有一个配置为在虚拟环境(Python 2.7.9)上运行的PyCharms python项目。 Off late , trying to debug the project on PyCharms used to throw import errors for many modules. 最近,尝试在用于引发许多模块导入错误的PyCharms上调试项目。 The code works just fine when invoked from a command prompt running same virtual env or while "Run"ing the project from PyCharms. 从运行相同虚拟env的命令提示符中调用,或从PyCharms“运行”项目时,该代码运行良好。 Upon inspection I found that for some reason PyCharms is invoking Python 2.7.10 and probably the third party dependencies are not installed in there !. 经过检查,我发现出于某种原因PyCharms正在调用Python 2.7.10,并且可能未在其中安装第三方依赖项!

My Question is, Is there a reason why PyCharms is moving away from the virtual env when invoking subprocess and what would be the best way to overcome this problem. 我的问题是,调用子流程时,PyCharms是否有脱离虚拟环境的原因,什么是克服此问题的最佳方法?

Here is the output of main process and subprocess when running from console/pycharms for the command 这是从控制台/ pycharms运行时该命令的主流程和子流程的输出

print __import__("sys").version

Sys version from Main Process!
2.7.9 (default, Feb 10 2015, 03:28:08) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)]

Sys version from Sub Process!
2.7.9 (default, Feb 10 2015, 03:28:08) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)]

And this is the output while debugging from the PyCHarms 这是从PyCHarms调试时的输出

print __import__("sys").version

Sys version from Main Process!
2.7.9 (default, Feb 10 2015, 03:28:08) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)]

Sys version from Sub Process!
2.7.10 (default, Jul 14 2015, 19:46:27) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)]

PyCharms version: PyCharms Community edition 4.5.3 PyCharms版本:PyCharms社区版4.5.3 在此处输入图片说明

Update with MacOSX ElCaptian update 使用MacOSX ElCaptian更新进行更新

With the introduction of new rootless feature with OSX ElCaptian ( https://apple.stackexchange.com/questions/193368/what-is-the-rootless-feature-in-el-capitan-really ) , it is no longer possible to alter python at /usr/bin , instead the better approach would be to just update PATH env variable from run configuration (Run->Edit Configuration->Environment->EnvironmentVariable and add/update PATH variable to /usr/local/bin:$PATH) 随着OSX ElCaptian( https://apple.stackexchange.com/questions/193368/what-is-the-rootless-feature-in-el-capitan-really )中引入的新无根功能,不再可能在/ usr / bin处更改python,更好的方法是从运行配置中更新PATH env变量(运行->编辑配置->环境-> EnvironmentVariable并将PATH变量添加/更新到/ usr / local / bin:$路径) 在此处输入图片说明


other way around 反过来

With little tinkering I was able to resolve the issue , may be it's not the correct way but it did solve the issue for me. 稍加修改,我就可以解决问题,也许这不是正确的方法,但确实为我解决了问题。

PyCharms while debugging somehow used invoke python from /usr/bin/ having python 2.7.10 instead of python 2.7.9 from /usr/local/bin . PyCharms在调试时以某种方式使用了从/ usr / bin /中调用python 2.7.10而不是从/ usr / local / bin中使用python 2.7.9的python。 Since All my path settings are correct and I do not rely upon 2.7.10 ,I rename python in "/usr/bin/" to python2.7.10 and created a symbolic link to python from /usr/local/bin in "/usr/bin" folder. 由于我的所有路径设置都是正确的,并且我不依赖2.7.10,因此我将“ / usr / bin /”中的python重命名为python2.7.10,并从“ / usr”中的/ usr / local / bin创建了指向python的符号链接/ bin”文件夹。

PyCharms now works like charm , but I still do not understand why it used to refer an external python bypassing the PATH settings and more-over why it has to invoke a python interpreter outside virtualenv when running a subprocess. PyCharms现在的工作方式就像charm一样,但是我仍然不明白为什么它过去常常绕过PATH设置来引用一个外部python,以及为什么它在运行子进程时必须在virtualenv之外调用一个python解释器。 Any idea's or hints on these questions are highly appreciated. 对于这些问题的任何想法或暗示都将受到高度赞赏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM