30

In PyCharm, after I run a script it automatically kills it:

C:\Users\Sean.virtualenvs\Stanley\Scripts\python.exe C:/Users/Sean/PycharmProjects/Stanley/Stanley.py

Process finished with exit code 0

How can I interact with the script after it starts? For lack of a better way to phrase it, how can I get the

>>>

prompt after the script runs once through?

  • PyCharm Community Edition 3.0
  • Windows 7
  • Python 2.7
1
  • will os.system('python') suffice? Or do you need to interact with the variables and objects within the script? Commented Oct 6, 2013 at 9:03

3 Answers 3

38

in Pycharm, Run/Debug menu choose Edit Configuration, check the box before 'Show command line afterwards'

Sign up to request clarification or add additional context in comments.

6 Comments

"thank you" * 1000! I was just looking at stackoverflow.com/questions/19329601/… and this is much, much easier than any of the answers there (though, if you are reading this before that be sure to check it out as the ability to interrupt via the debugger is great too!
Note: This feature is new in PyCharm 4.0, and received a bugfix in 4.0.1 or 4.0.2 to fix an issue with PYTHONPATH.
This is ALMOST perfect. It works only as long as the script does not throw an exception. Exceptions close the console. But this can be fixed by adapting the indirection script which Pycharm uses for execution: it is located in $PYCHARM_INSTALL_DIR/helpers/pydev/pydev_run_in_console.py Find the line that says "pydev_imports.execfile(file, globals, locals) # execute the script" and wrap it in a try...except block. Done.
This also does not work if your script has any raw_inputs for some reason (it just acts like Enter was immediately pressed)
With this solution, it is not possible to use the tab button to complete variable names. Is there any way to also add this functionality. With python -i script.py the tab can be used to complete variable names.
|
32

UPDATE
Starting with version 4.0 there's an option Show command line afterwards (renamed in later versions to Run with Python console) when editing run/debug configuration in Run|Edit Configurations....


From output of python --help:

-i : inspect interactively after running script; forces a prompt even if stdin does not appear to be a terminal; also PYTHONINSPECT=x

To set interpreter option in PyCharm go to Run|Edit Configuration

1 Comment

"Show command line afterwards" seems to be renamed to "Run with Python console", see this answer
11

Click Run -> Edit Configurations...,

Then check the box Run with Python console.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.