PyCharm 有变量浏览器吗

我最近将 Spyder作为 Python IDE 更改为 PyCharm。在 Spyder中,我经常使用变量浏览器特性(见图)。这个功能在 PyCharm中也可用吗?enter image description here

我发现这个 给你,“ Variable explorer in Python console (traff)”应该包括在 PyCharm 3,但我找不到。也许有人能告诉我怎么用那个工具。

138540 次浏览

The variable list is available in the python console Tools --> Run Python Console... as shown in the screen shot below. Similar functionality for showing variables and watched variables is available in the debugger console.

enter image description here

For your second question: you can also select your code and press shift + alt + E to run a part of your script on to the python console

I like Spyder for interacting with my variables and PyCharm for editing my scripts. Alternative Solution: use both simultaneously. As I edit in PyCharm (on Mac OS), the script updates live in spyder. Best of both worlds!

Right-click on the file and click Run file in console. Everytime you run it, the variables will show in the console until you click the stop button.

Step 1. Make a breakpoint by pressing on the right of the line numbers. Step 2. Click the debug button or right click then debug Step 3. Press the button above the settings button in the console to view the variables Step 4. Double click the variable of what you want to check the values. You can also right click that particular variable and view it as a dataframe.

The simple trick:

put any dummy line at the end of your code, e.g.

print('hi')

and set break point at this line.

Then, run your code in debug mode. Enjoy! The screenshots of editor and debug window are shown for your reference.

Editor window

Variables in debug window

PyCharm has SciView for exploring variables in almost exactly the same manner as Spyder. Simply execute the selection or cell in console, then click View as Array in the Special Variable pane. Special Variable Pane

If you want to view the complete dataset or an array do this:

  1. Go to python console in pycharm
  2. On the right usually, in the special variables tab, scroll down and find your data frame or csv you want to visualize.
  3. Right click on the data frame/dataset and see for the option view as array/data frame.
  4. There you go, you can see a tab opened containing your data.

If you want to inspect variables that contain arrays or datasets, like Spyder and see them as a nice table, you can do bellow :

1- Put a breakpoint after the variable that you like to inspect ( in my case, it's dataset) : enter image description here

2- Run the debugger ( the little bug on the top-right side of pyCharm).

The debugger will then stop on the line and you'll see something like below in your debugger window at the bottom of the pyCharm. enter image description here

3- Right click on the variable and select View As DataFrame

enter image description here

4- You then will be presented by a nice table like below :

enter image description here

The question is vague so this might be helpful to someone.

For me I managed to have the Console (so that printing in my script would be shown) AND the variable pane at the same time while in debug mode. For that I did this:

  1. Run code in debug mode
  2. Drag and drop the console into the debugger pane so that now both are together at the bottom pane.

Visual explanation fo what I did:

In (I assume default) debug mode:

enter image description here

during drag and drop:

enter image description here

and after finally I dropped it and it looks the way I want it:

enter image description here

If you want to inspect numpy arrays, which are images, you can use OpenCV Image Viewer Plugin.

https://plugins.jetbrains.com/plugin/14371-opencv-image-viewer

enter image description here

Disclaimer: I'm an author of this plugin