Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pycharm and subprocess - what works in console doesn't work in 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:

enter image description here

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?

like image 400
kurtgn Avatar asked Nov 21 '16 15:11

kurtgn


People also ask

How do I use Python console in PyCharm?

You can assign a shortcut to open Python console: press Ctrl+Alt+S , navigate to Keymap, specify a shortcut for Main menu | Tools | Python or Debug Console. The main reason for using the Python console within PyCharm is to benefit from the main IDE features, such as code completion, code analysis, and quick fixes.

How use subprocess command with pipes?

To use a pipe with the subprocess module, you have to pass shell=True . In your particular case, however, the simple solution is to call subprocess. check_output(('ps', '-A')) and then str. find on the output.

How do I clear the Python console in PyCharm?

In PyCharm terminal you can type 'cls' just like in linux terminal. You can also click somewhere on the PythonConsole -> Right button -> clear.

How do I restart PyCharm terminal?

From the main menu, select File | Manage IDE Settings | Restore Default Settings. Alternatively, press Shift twice and type Restore default settings . Click Restore and Restart. The IDE will be restarted with the default configuration.


1 Answers

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.

like image 108
Dan Cornilescu Avatar answered Sep 25 '22 19:09

Dan Cornilescu