我试图调试一个使用psutil.Popen对象的Python应用程序。当我启动子进程时,PyCharm将用以下命令行替换我的命令行:
python -m pydevd.py --multiproc --client 127.0.0.1 --port 52581 --file <myapplication>
结果是一个错误:
python.exe: Import by filename is not supported.
当我在没有-m
选项的情况下启动相同的命令时,一切似乎都很好。有没有方法可以更改PyCharm的调试器启动命令?
我已经更新到PyCharm Community Edition 4.0.3,新的调试器命令如下:
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
其中-c
和-f
是模块的命令行参数。调试器启动命令已更改,但它没有解决问题;我仍然收到Import by filename is not supported
错误。
有一个代码示例here at Bitbucket.org。 Pycharm的运行配置应该如下所示:
Script: __main__.py
Script parameters: server
Working directory: %path to the repository%
如Piotr所述,PyCharm“在调试时自动附加到子进程”。如果子进程是Python进程,PyCharm调试器将更改进程的启动参数(请参见位于source的函数
patch_args
)。以这种方式启动子流程时:实际的启动命令如下:
所以出了问题。我可以找到几个解决方法:
最简单的方法是,如果不需要调试子流程,只需在PyCharm设置中关闭“调试时自动附加到子流程”
将参数更改为:
缺点是只能运行Python文件,不能运行Python模块。
我推荐Python子进程的最后一个解决方案:
相关问题 更多 >
编程相关推荐