Debugging a python process from InteliJ

Answered

Hi guys,

 

I have a java project, maintained on InteliJ.

From this project there is a shell cmd call which calls a python script, which I am maintaining on PyCharm.

What I do is, I stop right before that call, and create a debug configuration on PyCharm with the cmd parameters.Then I am executing the python code step by step.

Of course this is not ideal. After I process my python code n PyCharm, I cannot (or at least don't know how) continue the flow on InteliJ.

So, do you have a nice solution for me?

 

Thanks!

0
4 comments

Hi Tal,

IntelliJ IDEA Ultimate provides full Python support (same as PyCharm Professional).

You can install and configure the Python plugin, add a new Python module to your existing Java project and copy your Python sources over to it, then make Java module dependent on Python module, and eventually call the script directly from within the same project. You will also have a dedicated Python run/debug configuration.

See the following comment for more information:

0

Hi Arina,

I added mylre-events python module to the intelij project along with my java project.

Currently I am calling a py file which is in lre_events from pcn-qa-data-script-test by using a command shell:

cmd /c "cd /d c:\Users\username\gitwork\lre-events\venv\Scripts & activate & cd /d c:\Users\username\gitwork\lre-events & python filename.py

I put a breakpoint on the py file and tried to execute the java code which calls the py code, but the execution did not reach the python breakpoint (as I expected).

Obviously I didn't configure the projects correctly. 

Could you please explain to me exactly the steps I should do in order to call the python code from the Java code so I would hit the python breakpoint?

Regards, Tal

 

 

 

0

Hi Tal,

Unfortunately, one cannot use Java's debugger to step through the Python code. You can, however, run the Remote Debug Server configuration and add the "connection lines" to your Python code so that as soon as it's called by your Java code, the connection is established with the Python debugger. This way you should be able to step through your Python code just fine.
See https://www.jetbrains.com/help/idea/remote-debugging-with-product.html#remote-debug-config

Let me know if it works for you.

0

Thanks, I'll try.

0

Please sign in to leave a comment.