the python path in your debug_Intellij / Pycharm无法调试Python模块

I use PyCharm/IntelliJ community editions from a wile to write and debug Python scripts, but now I'm trying to debug a Python module, and PyCharm does a wrong command line instruction parsing, causing an execution error, or maybe I'm making a bad configuration.

This is my run/debug configuration:

And this is executed when I run the module (no problems here):

/usr/bin/python3.4 -m histraw

But when I debug, this is the output in the IntelliJ console:

/usr/bin/python3.4 -m /opt/apps/pycharm/helpers/pydev/pydevd.py --multiproc --client 127.0.0.1 --port 57851 --file histraw

/usr/bin/python3.4: Error while finding spec for '/opt/apps/pycharm/helpers/pydev/pydevd.py' (: No module named '/opt/apps/pycharm/helpers/pydev/pydevd')

Process finished with exit code 1

As you can see, the parameters are wrong parsed, and after -m option a IntelliJ debug script is passed before the module name.

I also tried just put -m histraw in the Script field, but doesn't work, that field is only to put Python script paths, not modules.

Any ideas?

解决方案

There is another way to make it work.You can write a python script to run your module.Then just configure PyCharm to run this script.

import sys

import os

import runpy

path = os.path.dirname(sys.modules[__name__].__file__)

path = os.path.join(path, '..')

sys.path.insert(0, path)

runpy.run_module('', run_name="__main__",alter_sys=True)

Then the debugger works.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值