问题描述
Pycharm 的解释器似乎无法理解我的一些控制台命令.它不断识别默认的 shell 命令,但无法识别已安装的实用程序.
例如,subprocess
模块理解 touch
命令但不理解 heroku
命令.
有趣的是,当我使用相同的解释器(来自同一个 virtualenv)在控制台中输入相同的字符串时,一切正常.
视觉示例:
几天前它停止工作,在此之前一切正常.
我以为我弄乱了我的一些环境变量,但打开了一个我已经一个月没有碰过的旧项目,发现相同的 subprocess
命令也在那里停止工作.>
可能是什么问题?
更新
好的,我让这件事起作用了.
os.environ['PATH']
的值在控制台和 Pycharm 中是不同的.在我将正确的 PATH 添加到 Pycharm 配置环境变量后,一切又开始工作了.
现在的问题是,我如何避免在我的每个项目中检查每个配置并在任何地方添加这个新的 PATH?有没有办法全局执行此操作并修复这个唯一已损坏的设置?
我看到你想出了如何配置 PyCharm 的项目路径.
至于如何不必为您启动的每个项目新项目都这样做,您只需要更新您的默认项目配置.
来自访问默认设置:>
PyCharm 有助于定义默认项目的设置.这些设置每次创建新项目时都用作默认值.
访问默认项目设置
- 在主菜单上,选择文件|默认设置
- 在设置中定义所需的设置对话框打开.
注意:对默认项目配置的更新仅适用于未来的新项目,任何现有项目配置都需要手动更新.
Pycharm's interpreter seems to have stopped understanding some of my console commands. It keeps recognizing default shell commands but doesn't recognize installed utilities.
For example, subprocess
module understands touch
command but doesn't understand heroku
command.
The funny thing is, when I enter the same string into the console, with the same interpreter (from the same virtualenv), everything works fine.
A visual example:
It stopped working a couple days ago, and before that everything had worked fine.
I thought I had messed up some of my env vars, but opened an old project I hadn't touched for a month, and saw that the same subprocess
commands stopped working there too.
What could be the problem?
UPDATE
Ok, I got this thing to work.
The values of os.environ['PATH']
were different in console and in Pycharm. After I added the correct PATH to the Pycharm configuration env vars, everything started working again.
Now the question is, how do I avoid going through each configuration in each and every of my projects and adding this new PATH everywhere? Is there a way to do this globally and repair this one only setting that's been broken?
I see you figured out how to configure PyCharm's project PATH.
As for how to not have to do this for every project new project you start, you just have to update your default project configuration.
From Accessing Default Settings:
Note: updates to the default project configurations only apply to future new projects, any existing project configuration needs to be updated manually.
这篇关于pycharm 和子进程 - 在控制台中有效的方法在 Pycharm 中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!