如何将ipython / jupyter设置为vscode的默认python终端?

Fra*_*ues 2 python ipython jupyter visual-studio-code

如何选择ipython / jupyter作为DEFAULT python终端?我将Windows 10和Linux计算机与anaconda一起使用。

如果我在终端上键入“ ipython”,它将打开一个ipython会话。如果运行调试器或Shift + Enter一行,它将自动在“准系统” python外壳程序上运行。应该很简单...但是我一直在搜索和弄乱设置达半小时,但没有成功。

抬头

https://code.visualstudio.com/docs/python/tutorial-flask

在VS Code中使用IPython REPL

但找不到在我的linux或win10机器上进行设置的方法。有任何想法吗?

小智 9

实现@TwoUnderscorez答案的一种更简洁的方法是仅使用以下命令启动模块-m IPython

"python.terminal.launchArgs": [
   "-m",
   "IPython"
]
Run Code Online (Sandbox Code Playgroud)

编辑:对于任何遇到IndentationError: unexpected indent错误的人,请尝试以下操作:

"python.terminal.launchArgs": [
   "-m",
   "IPython",
   "--no-autoindent",
]
Run Code Online (Sandbox Code Playgroud)

(不会只是在现有答案中添加评论,但代表人数不足)


小智 6

  1. 在你的 VSCode 中,按ctrl+shift+P,开始输入设置并点击Preferences: Open Settings (JSON)

  2. 添加这个键值对来告诉 python 启动 ipython:

    "python.terminal.launchArgs": [
        "-c",
        "\"from IPython import start_ipython; start_ipython()\""
    ]
    
    Run Code Online (Sandbox Code Playgroud)


Bre*_*non 5

目前不支持指定不是用于执行代码的 Python 解释器的替代 REPL。如果您只想将代码发送到 REPL,有些人会采取的一个技巧是,他们启动 REPL 一次,退出它,然后ipython手动启动,因为扩展将继续使用该终端实例来发送到 REPL 的未来代码。

  • 仅供将来参考,我在 Linux 机器上遇到此解决方法的问题。当我尝试选择并运行(Shift+Enter)多行代码时,它仅运行第一行。由于这些限制,我发现自己越来越多地使用 jupyternotebook。这是一个奇怪的工作流程。 (2认同)