27

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.

  • When an error occurs I get something like this:
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.

  • When running a file IPython needs to be started which takes some seconds even if I'm not going use the interpreted afterwards. I would like PyCharm to start IPython after the program has ended or when I start debugging (you can start IPython in an interactive console by doing 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.

EDIT:

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.

ZF007
  • 3,708
  • 8
  • 29
  • 48
0x539
  • 1,489
  • 1
  • 13
  • 30
  • I am intrigued by the bounty, but unfortunately I am at a loss as to what the question is. It sounds like you have bug reports/feature requests for pycharm? – Jonah Graham Nov 02 '15 at 19:53
  • @JonahGraham these aren't strictly bugs they are behaviour I would like to change. And I suppose that most of it can be changed, at least if you are willing to edit some source – 0x539 Nov 03 '15 at 17:05
  • 1
    You have already put in your +100 reps for this, I hope someone rewrites the code for you to do these things. However, I would still expect more luck on creating bug reports/feature requests with PyDev or PyCharm, especially as you are actually paying for PyCharm :-) – Jonah Graham Nov 03 '15 at 17:12
  • @JonahGraham I'm not paying for it; I'm a student – 0x539 Nov 03 '15 at 20:29
  • Do these things work better in PyDev in Eclipse - it certainly seems PyDev is more up to date that PyCharm. (as you are using pro edition of pycharm I assumed you were paying for it, well done getting a free license), finally I am not up on PyCharm versions (AFAIK they have three active major versions, 3.x, 4.x and 5.x, have you tried the 5.x to see if your issues are better there?) – Jonah Graham Nov 03 '15 at 21:34
  • It seems like a bug on pycharms/Ipythons consider contacting the developers or using just one of these softwares or export it to github or somthing, not likly to fix it but its somthing to try, try reinstalling python and your programs – Jo-Tech Games Aug 07 '19 at 13:26

2 Answers2

1

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:

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
0

In all honesty, have you simply tried running a newer version of PyCharm and importing your settings? 3.5 is fairly outdated (I'm on 4.5.3 myself, newest version is 5.0) and I believe more support is offered for IPython in the newer versions. https://www.jetbrains.com/pycharm/help/ipython.html. Especially if you are a student, it might not hurt to give it a shot. I know older versions of PyCharm were more buggy than recent releases.

AndrewSmiley
  • 1,933
  • 20
  • 32