Plugin Debugging mit Pycharm

Hi,

as my plugin become complex with thread management and so on I setup an Pycharm IDE with a local installation of Octoprint on my Windows Laptop instead of testing it on my Pi. But I ask me how at best set a breakpoint to my plugin which is under the AppData folder in windows. As I am new to Python and also Pycharm hopefully you can give me a hint to get the plugin debugging running and also about the project structure with the plugins. I followed the guide here: Setting up a Development environment β€” OctoPrint master documentation

Actual situation:

  • Starting OctoPrint in Pycharm is possible and a debugger could be attached, breakpoint working fine
  • Did not know how to set a breakpoint in my plugin?

Cheers,
Nils

If you have the debug configuration for OctoPrint, this will work too for your plugin.

Open the plugin's folder as the Pycharm project, and configure the debug settings for this to run OctoPrint (Note: You can also attach it to OctoPrint, but I find this more of a pain).

Then to add a breakpoint, click:image

Then when you run from this project, you should be fine to debug and hit the breakpoints.

I tried to add the folder (within AppData) but the breakpoints are not reached. (would be nice so set breakpoints in Octoprint). I also tried like you advised creating a new project with the plugin folder but it shows the same behaviour. Also I cannot configure the virtual env. but Octoprint is starting.

grafik

I hope this questions are not very stupid. :slight_smile:

The second one is how I use it. The key is that you have to configure the virtual environment and the run/debug configuration in that project, then run OctoPrint from there, it won't stop on breakpoints if you run OctoPrint outside the project that has the breakpoints in.

If I move the virt env to the plugin folger I cannot start octoprint anymore. Could you perhaps post a screenshot of your configuration.

Connected to pydev debugger (build 203.7148.72)
No module named octoprint

I will try and explain it, we will see how it goes.

Leave the virtualenv right where it is. If that works, that is fine.

Then register the virtual environment with PyCharm:


And make sure it is selected:

You can then create the run/debug configuration:

Make sure you have the original Python interpreter selected, where you have installed OctoPrint and your plugin.

That's all I have for it, using PyCharm Professional so hopefully there are not too many differences if you are using the community edition.

1 Like

Now it is running fine, many thanks. Perhaps this should be added in the official development doc. It is the same with community edition.

To understand Pycharm Debugging it is still interesting for my why all other variants like adding the folder to the OctoPrint project does not work. This solution does use the same virt. env. and configuration. Actually I copied it to the project contains my plugin only and it is running well!? What is the dfference?

Another problem...only sometimes I get an error with the external program calls that are recommended by the Octoprint guide. As it is running fine mostly I think it is not a general problem. Do you know this perhaps?

05:54 Error running 'cleanup': Executable is not specified

It seems that the variable %ModuleSdkPath% is empty.