I have PyCharm Professional Edition 3.5 5.0 configured to
use IPython when possible
and in my Run/Debug Configurations I set
show interpreter afterwards
I use the interactive Interpreter a lot and I really like IPython, but there are some things that I don't like about the way this is handled in PyCharm:
any input()
in my programs return empty strings.
Additionally, when an error occurs I can't interact with the Program anymore. (you can when you run a Python program with the -i
flag)
There is a lot of space between the last line in the Console and the current line
In IPython the ...:
prompt in a code block isn't indented 2 spaces and therefore not aligned to the In [?]:
prompt.
Traceback (most recent call last): File "C:\Program Files (x86)\PyCharm\helpers\pydev\pydev_run_in_console.py", line 69, in <module> globals = run_file(file, None, None) File "C:\Program Files (x86)\PyCharm\helpers\pydev\pydev_run_in_console.py", line 29, in run_file pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Program Files (x86)\PyCharm\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "C:/Users/ca/Python/Bundeswettbewerb Informatik/Aufgabe2/Ameisen.py", line 133, in <module> function_that_caused_error()
I don't need/want to see the traceback from the internals.
import IPython; IPython.start_ipython()
There are some other minor things that I don't like:
When IPython is started it prints a lot of text to the console. I don't want to see any of it except maybe the version number (you can usually do this with the --no-banner
option, but adding it to the interpreter options doesn't work)
when you type something and press Up
it replaces what I have written with the last item of my history instead of replacing it with the last item of my history that start with what I have typed. Plain IPython does this.
I would like to have automatic code completion without having to press Ctrl + Space
in the console
The "problems" are ordered by importance. Does anybody know how to change some of them? I could stop using IPython which would solve the second , the third and the fourth problem, but the other ones would still persist. All of this behavior (excluding the IPython stuff) is implemented very well in PyScripter.
I have found solutions to the first two problems and the problem with the IPython banner. The source for the PyDev interactive interpreter (which is used by PyCharm) is located, on Windows, in C:\Program Files (x86)\PyCharm\helpers\PyDev
(path my vary of course).
So the first problem can be solved by editing the file _pydev_imps/_pydev_execfile.py
. Wrap line 18 (exec(compile(contents+"\n", file, 'exec'), glob, loc)
) in a try ... except
block with the following code as the exception handler import traceback; traceback.print_exc()
. This will terminate your Python program if there is an error while letting you interact with the variable afterwards.
Problem 2 can be solved by editing the fire pydev_run_in_console.py
. Add this import at the beginning of the file: from pydev_console_utils import StdIn
and insert sys.stdin = StdIn(interpreter, host, client_port)
after what was line 61 before adding the import.
In order to solve the problem with the banner you have to download the most recent version of the PyDev source here and replace the files pydev_ipython_console
and pydev_ipython_console_011
by their newer versions. In the newer version of the first file the __init__
method in line 22 has a argument called show_banner
with the default value True
. Change this to False
.
This is probably not the answer you are searching for, but based on my experience using IPython
on InteliJ products ( PyCharm
, Ultimate
), I don't recommend using their version of IPython
. It's full of bugs, outdated and you'll lose precious time fixing problems instead of coding.
Have you tried jupyter notebook
? If you installed python
with anaconda
, it's already installed. To run it, open the terminal and type:
jupyter notebook
If your browser doesn't open automagically, head to http://localhost:8888
Note:
You can automate this process by creating bat
or sh
script containing the code above inside your project directory, this way it doesn't start on you home dir, which it does by default.
Resources:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With