Use IPython REPL in VS Code

2019-04-26 20:56发布

Using the Python extension of Visual Studio Code, I can select some code, right-click it, and select "Run Selection/Line in Python Terminal" (alternatively, I can hit Shift+Enter). However, this sends the selected code to a plain old Python REPL in the Terminal pane, whereas I'd like to have this code run in IPython instead (not the QtConsole, just the terminal-based IPython).

Is it possible to set IPython as the default REPL? I tried setting /usr/local/bin/ipython3 as my default Python environment, but that doesn't work (it still executes the plain Python interpreter). FWIW, I'm on macOS.

3条回答
我欲成王,谁敢阻挡
2楼-- · 2019-04-26 21:36

IPython support is provided by "IPython for VSCode" plugin.

Just select the text and invoke 'Send Selected Text (or current line) To IPython' in command palette.

Also official Microsoft Python plugin now supports interactive Jupiter windows, with similar functionality.

查看更多
祖国的老花朵
3楼-- · 2019-04-26 21:39

Type Ipython inside the terminal window. Then select the line or lines you want to run from the editor window and then click on the Terminal menu at the top of VScode window. One option in the Terminal menu is to "Run Selected Text". This will be run in the Ipython terminal window. I don't know how to make this the default but it appears to remain in that state unless Ipython is stopped. Note: You have to run your selections using the Menu item. Right-clicking in the editor window and clicking on "Run Selection" will not use the Ipython window. I hope this is clear. If not just drop a comment.

查看更多
霸刀☆藐视天下
4楼-- · 2019-04-26 21:45

I start IPython from inside the standard Python REPL that's spawned by Shift-Enter with

import IPython
IPython.embed()

See IPython docs.

查看更多
登录 后发表回答