pycharm 和子进程 - 在控制台中有效的在 Pycharm 中无效 [英] pycharm and subprocess - what works in console doesn't work in Pycharm

查看:54
本文介绍了pycharm 和子进程 - 在控制台中有效的在 Pycharm 中无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Pycharm 的解释器似乎已经停止理解我的一些控制台命令.它不断识别默认的 shell 命令,但不识别已安装的实用程序.

例如,subprocess 模块理解 touch 命令但不理解 heroku 命令.

有趣的是,当我使用相同的解释器(来自相同的 virtualenv)在控制台中输入相同的字符串时,一切正常.

一个直观的例子:

它在几天前停止工作,在此之前一切正常.

我以为我搞砸了一些环境变量,但打开一个我一个月没碰过的旧项目,发现相同的 subprocess 命令也停止工作了.

可能是什么问题?

更新

好的,我得到了这个东西.

os.environ['PATH'] 的值在控制台和 Pycharm 中是不同的.在我将正确的 PATH 添加到 Pycharm 配置环境变量后,一切又开始工作了.

现在的问题是,我如何避免在每个项目中都进行每个配置,并在任何地方添加这个新的 PATH?有没有办法在全局范围内执行此操作并修复已损坏的唯一设置?

解决方案

我看到你想出了如何配置 PyCharm 的项目 PATH.

至于如何不必为你开始的每个项目新项目都这样做,你只需要更新你的默认项目配置.

来自访问默认设置:p><块引用>

PyCharm 帮助定义默认项目的设置.这些设置每次创建新项目时都将其用作默认值.

访问默认项目设置

  1. 在主菜单上,选择文件|默认设置
  2. 设置中定义所需的设置对话框.

注意:默认项目配置的更新仅适用于未来的新项目,任何现有的项目配置都需要手动更新.

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:

PyCharm helps define settings of a default project. These settings are used as defaults every time you create a new project.

To access default project settings

  1. On the main menu, choose File | Default Settings
  2. Define the desired settings in the Settings dialog box that opens.

Note: updates to the default project configurations only apply to future new projects, any existing project configuration needs to be updated manually.

这篇关于pycharm 和子进程 - 在控制台中有效的在 Pycharm 中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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