【问题标题】:PyCharm debugger doesn't workPyCharm 调试器不起作用
【发布时间】:2022-05-04 17:30:53
【问题描述】:

我刚刚下载了 PyCharm 社区版,每次尝试在 PyCharm 中调试任何 Python 程序时,都会收到此错误:

C:\Python31\python.exe "C:\Program Files (x86)\JetBrains\PyCharm Community 
Edition 2016.1\helpers\pydev\pydevd.py" --multiproc --qt-support --client 127.0.0.1 --port 59207 --file C:/Users/Gal/PycharmProjects/untitled/test.py
pydev debugger: process 5388 is connecting

Connected to pydev debugger (build 145.260)
Traceback (most recent call last):
  File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.1\helpers\pydev\pydevd.py", line 1530, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.1\helpers\pydev\pydevd.py", line 937, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.1\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 11, in execfile
    stream = tokenize.open(file)  # @UndefinedVariable
AttributeError: 'module' object has no attribute 'open'

打开一个名为“_pydec_excecfile.py”的python文件:

#We must redefine it in Py3k if it's not already there
def execfile(file, glob=None, loc=None):
    if glob is None:
        import sys
        glob = sys._getframe().f_back.f_globals
    if loc is None:
        loc = glob
# It seems that the best way is using tokenize.open(): http://code.activestate.com/lists/python-dev/131251/
import tokenize
stream = tokenize.open(file)  # @UndefinedVariable
try:
    contents = stream.read()
finally:
    stream.close()

#execute the script (note: it's important to compile first to have the filename set in debug mode)
exec(compile(contents+"\n", file, 'exec'), glob, loc)

我该如何解决?

【问题讨论】:

标签: python python-3.x debugging ide pycharm


【解决方案1】:

我在一个项目中遇到了类似的情况,该项目有一个名为“tokenizer.py”的文件。 尝试在同一个项目中调试不同的 Python 代码时(即使在不同的文件中),我得到以下错误输出:

Traceback (most recent call last):

File "C:\Programs\PyCharm\plugins\python-ce\helpers\pydev\pydevd.py", line 1483, in _exec 

pydev_imports.execfile(file, globals, locals)  # execute the script
File "C:\Programs\PyCharm\plugins\python-ce\helpers\pydev\_pydev_imps  \_pydev_execfile.py", line 11, in execfile 
stream = tokenize.open(file)  # @UndefinedVariable 

AttributeError: module 'tokenize' has no attribute 'open'

我可以运行代码,但不能调试它。然后我在link 找到了一个讨论,这个想法是代码中的一个模块隐藏了调试器所需的一些顶级包。我重命名了“tokenizer”模块,再次可以进行调试。 这似乎是秘诀:尝试重命名错误输出中提到的模块。

【讨论】:

    猜你喜欢
    • 2021-08-28
    • 2016-11-23
    • 1970-01-01
    • 1970-01-01
    • 2013-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-21
    相关资源
    最近更新 更多