如何在 IPython 控制台中默认运行文件而不是终端?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42562734/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run a file in IPython console as default instead of terminal?
提问by ilpomo
I started a new project in PyCharm. I have Anaconda 3.6 installed. So, in PyCharm, I selected the Anaconda python.exe as project interpreter.
我在 PyCharm 中开始了一个新项目。我安装了 Anaconda 3.6。因此,在 PyCharm 中,我选择了 Anaconda python.exe 作为项目解释器。
When I first ran PyCharm, it used the IPython console as "default" console to run my script. Then I restarted my PC and now PyCharm uses the terminal when I run my scripts. Why? I don't want to use the terminal, coming from Anaconda Spyder IDE. I'm used to IPython, I like it and I want to use it.
当我第一次运行 PyCharm 时,它使用 IPython 控制台作为“默认”控制台来运行我的脚本。然后我重新启动了我的电脑,现在 PyCharm 在我运行我的脚本时使用终端。为什么?我不想使用来自 Anaconda Spyder IDE 的终端。我习惯了 IPython,我喜欢它,我想使用它。
How can I completely disable the terminal and use only the IPython console?
如何完全禁用终端并仅使用 IPython 控制台?
回答by vestland
Short answer:
简短的回答:
- Go to
File > Default settings > Build, Execution, Deployment > Console
and selectUse Ipython if available
- Go to
Run > Edit Configurations
and selectShow command line afterwards
- 前往
File > Default settings > Build, Execution, Deployment > Console
并选择Use Ipython if available
- 前往
Run > Edit Configurations
并选择Show command line afterwards
Tip: Run selected parts of your code with ALT+ SHIFT+ E
提示:选择运行你的代码的部分ALT+ SHIFT+E
The details:
细节:
If you've selected Anaconda
as the project interpreter, IPython will most likely be the selected console even though it neither looks nor behaves like the IPython console you are used to in Spyder
:
如果您已选择Anaconda
作为项目解释器,则 IPython 很可能是选定的控制台,即使它的外观和行为都不像IPython console you are used to in Spyder
:
Unlike Spyder, PyCharm has no graphical indicator
showing that this is an IPython console.
与 Spyder 不同,PyCharm has no graphical indicator
显示这是一个 IPython 控制台。
To make sure it's an IPython console and make it behave more or less like the IPython console you are used to from Spyder, you should follow these two steps:
为了确保它是一个 IPython 控制台并使它的行为或多或少像你在 Spyder 中习惯的 IPython 控制台,你应该遵循以下两个步骤:
Go to
File > Default Settings > Build, Execution, Deployment > Console
and make sure to selectUse IPython if available
.Go to
Run > Edit Configurations
and selectShow command line afterwards
Now you can run selected parts of your code with ALT+SHIFT+E
more or less exactly like in Spyder.
现在,您可以ALT+SHIFT+E
或多或少地像在 Spyder 中一样运行代码的选定部分。
If this doesn't do the trick, you should check out these other posts on SO:
如果这不起作用,您应该查看 SO 上的其他帖子:
Interacting with program after execution