NewbieCoder
NewbieCoder

Reputation: 11

How can I use Pycharm to debug a Python script run by another program

I'm using python as a scripting language for game logic in the coco2d-x game engine. I know how to debug python scripts in Pycharm.

How can I debug my python scripts when they are called by another program? In my case, it's a simulator provided by the game engine. If scripts are not started inside Pycharm, can Pycharm still somehow capture the scripts' excecuting process?

I tried to use "attach to a local process", but can't find any. I've read related topics like "how to step through python code","remote debug". But can't find similar topics that address my problem.

Upvotes: 0

Views: 507

Answers (1)

NewbieCoder
NewbieCoder

Reputation: 11

I found a solution for this myself. I used the Remote Debug mentioned in the question.

  1. Set the "Local host name" to "localhost" and set the port.
  2. Then extract the "pycharm-debug-py3k.egg" file to some directory.
  3. Start the Game.exe with args "-debug %EGG_PATH% %PYTHON_PATH% %PORT%".

In the python project you have to write the following code for this to work.

sys.path.append("<path to python>")
sys.path.append("<path to python>/Lib")
sys.path.append("<path to python>/DLLs")
sys.path.append("<path to pycharm-debug.egg>">
import pydevd
pydevd.settrace(host="localhost", port=<your port>, suspend=False, stdoutToServer=True, stderrToServer=True)

This only works if the caller program supports something like the "-debug" arg in my case.

My question is kind of a duplicate of this one. debugging a uwsgi python application using pycharm

Upvotes: 1

Related Questions