I'm trying to debug a Python application that uses psutil.Popen objects. When I start a subprocess, PyCharm replaces my command line with the following:
python -m pydevd.py --multiproc --client 127.0.0.1 --port 52581 --file <myapplication>
which ends up in an error:
python.exe: Import by filename is not supported.
When I launch the same command without -m
option, everything seems to be fine. Is there a way I can change PyCharm's debugger launch command?
I've updated to PyCharm Community Edition 4.0.3 and the new debugger command looks like:
python.exe "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.0.3\helpers\pydev\pydevd.py"
--multiproc --client 127.0.0.1 --port 62661
--file __main__.py local -c local.yml -f input/11_12.xls
where -c
and -f
are my module's command line arguments. The debugger launch command has changed, but it didn't solve the issue; I still get the Import by filename is not supported
error.
A code example is available here at Bitbucket.org. Pycharm's run configuration should look like:
Script: __main__.py
Script parameters: server
Working directory: %path to the repository%
As Piotr mentioned, PyCharm 'Attach to subprocess automatically while debugging'. If subprocess is a Python process, PyCharm debugger change the process's startup arguments (see function
patch_args
at source). When you start subprocess in this way:The actual startup command is like:
So it went wrong. There are several workarounds I can find:
easiest way, if you don't need to debug subprocess, just turn off "Attach to subprocess automatically while debugging" inside PyCharm settings
change your args to:
The disadvantage is you can only run a Python file, not a Python module.
I recommend the last solution for Python subprocess: