在PyCharm中运行Program后显示Interpreter(IPython)时出现的问题 [英] Problems when showing Interpreter (IPython) after running Program in PyCharm

查看:4481
本文介绍了在PyCharm中运行Program后显示Interpreter(IPython)时出现的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有PyCharm专业版 3.5 5.0配置为

I have PyCharm Professional Edition 3.5 5.0 configured to


尽可能使用IPython

use IPython when possible

在我的运行/调试配置中我设置

and in my Run/Debug Configurations I set


show后来的翻译

show interpreter afterwards

我经常使用交互式解释器,我真的很喜欢IPython,但有一些我不喜欢的事情在PyCharm中处理它的方式:

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.

此外,当发生错误时,我无法再与程序交互。 (你可以在运行带有 -i 标志的Python程序时)

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

在IPython中。 ..:代码块中的提示没有缩进2个空格,因此没有与 In [?]:提示符对齐。

In IPython the ...: prompt in a code block isn't indented 2 spaces and therefore not aligned to the In [?]: prompt.


  • 当出现错误时,我得到类似这样的东西

    Traceback(最近一次电话会议) last):
    文件C:\Program Files(x86)\PyCharm \helpers\pydev\pydev_run_in_console.py,第69行,< module>
    globals = run_file(file,None,None)
    文件C:\Program Files(x86)\PyCharm \helpers\pydev\pydev_run_in_console.py,第29行,在run_file中
    pydev_imports.execfile(文件,全局,本地)#执行脚本
    文件C:\Program Files(x86)\PyCharm \helpers\pydev\_pydev_imps \_pydev_execfile.py ,第18行,在execfile中
    exec(编译(内容+\ n,文件,'exec'),glob,loc)
    文件C:/ Users / ca /​​ Python / Bundeswettbewerb Informatik /Aufgabe2/Ameisen.py,第133行,< module>
    function_that_caused_error()

    我不需要/想要从内部看到回溯。

  • 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.

当运行文件时,需要启动IPython,即使我之后没有使用解释,也需要几秒钟。我希望PyCharm在程序结束或我开始调试后启动IPython(你可以通过 import IPython在IPT中创建IPython; IPython.start_ipython()

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


  • 当启动IPython时,它会向控制台输出大量文本。除了版本号之外,我不希望看到任何文本(你通常可以使用 - no-banner 选项,但将其添加到解释器选项不起作用)

  • 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)

当你输入内容并按下 Up 时,它会替换我用历史记录的最后一项写的内容,而不是用我的历史记录的最后一项替换它。类型。普通IPython这样做。

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.

我希望自动代码完成,而不必按 Ctrl + Space 在控制台中

I would like to have automatic code completion without having to press Ctrl + Space in the console

问题按重要性排序。有人知道如何更改其中一些吗?我可以停止使用IPython来解决第二个,第三个和第四个问题,但其他问题仍然存在。所有这些行为(不包括IPython的东西)都在PyScripter中很好地实现。

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找到了前两个问题的解决方案以及IPython横幅的问题。 PyDev交互式解释器(由PyCharm使用)的源位于Windows上的 C:\Program Files(x86)\ PyCharm \ helpers \ PyDev (路径我当然不一样)。

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).

因此,第一个问题可以通过编辑文件 _pydev_imps / _pydev_execfile.py 来解决。在尝试中换行第18行( exec(compile(contents +\ n,file,'exec'),glob,loc))。 ..除了块,使用以下代码作为异常处理程序 import traceback; traceback.print_exc()。如果在以后让你与变量交互时出现错误,这将终止你的Python程序。

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.

问题2可以通过编辑火来解决 pydev_run_in_console.py 。在文件开头添加此导入:从pydev_console_utils导入StdIn 并插入 sys.stdin = StdIn(interpreter,host,client_port)在添加导入之前的第61行之后。

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.

为了解决横幅问题,你必须下载最新版本的PyDev源代码此处并使用新版本替换文件 pydev_ipython_console pydev_ipython_console_011 。在第一个文件的较新版本中,第22行中的 __ init __ 方法有一个名为 show_banner 的参数,其默认值为。将此更改为 False

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.

推荐答案

老实说,你干脆尝试运行更新版本的PyCharm并导入您的设置? 3.5已经过时了(我自己4.5.3,最新版本是5.0)我相信在新版本中会为IPython提供更多支持。 https://www.jetbrains.com/pycharm/help/ipython.html 。特别是如果你是一名学生,那么试一试就不会有什么坏处。我知道较旧版本的PyCharm比最近发布的版本更加错误。

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.

这篇关于在PyCharm中运行Program后显示Interpreter(IPython)时出现的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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