简体   繁体   English

如何在 VSCode 的窗格中显示 python 环境对象?

[英]How to show python environment objects in a pane in VSCode?

In R Studio, Matlab, and in some Python IDEs (like Thonny) you can see a list of the variables in your environment, together with some summary information like values, type etc.在 R Studio、Matlab 和一些 Python IDE(如 Thonny)中,您可以看到环境中的变量列表,以及一些摘要信息,如值、类型等。

Is there a way to do this in VSCode without going into debugging mode?有没有办法在不进入调试模式的情况下在 VSCode 中做到这一点?

VS Code has an IPython mode with a dropdown box called Variables that basically does exactly this. VS Code 有一个 IPython 模式,带有一个名为Variables的下拉框,基本上就是这样做的。

To enter IPython mode all you need to do is highlight a piece of code and hit Shift+Enter要进入 IPython 模式,您需要做的就是突出显示一段代码并按Shift+Enter

The first time you do it there might be a bit of setting up to do but it was pretty easy to get it working on my Mac.第一次这样做时,可能需要进行一些设置,但在我的 Mac 上使用它非常容易。 Not sure what it's like on Windows/Linux though不知道它在 Windows/Linux 上是什么样的

Note: When I use VS Code I open it from the terminal (simply enter the command 'code') after I've activated my conda environment.注意:当我使用 VS Code 时,我会在激活 conda 环境后从终端打开它(只需输入命令“代码”)。 That way the IPython interpreter uses my preferred conda environment when it launches.这样,IPython 解释器在启动时就会使用我喜欢的 conda 环境。

Seems like the closest as it gets to the RStudio Environment window is by installing Jupyter.似乎最接近 RStudio 环境窗口的是安装 Jupyter。 Then you can type #%% in your .py file and a small "Run Cell" button will appear.然后你可以在你的 .py 文件中输入#%%并且会出现一个小的“运行单元”按钮。 Running the cell will open the "Python Interactive Window".运行单元格将打开“Python 交互窗口”。 There you can click the "See Variables Active" button to open up the Variable Window and see your variables... still a bit painful in comparison with RStudio, this should be integrated in VScode's IDE.在那里你可以点击“See Variables Active”按钮打开变量窗口并查看你的变量......与RStudio相比仍然有点痛苦,这应该被集成到VScode的IDE中。

See steps here: https://code.visualstudio.com/docs/python/jupyter-support-py#_variable-explorer-and-data-viewer请参阅此处的步骤: https : //code.visualstudio.com/docs/python/jupyter-support-py#_variable-explorer-and-data-viewer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM