Gal*_* A. 5 python ide debugging pycharm python-3.x
我刚刚下载了 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'
Run Code Online (Sandbox Code Playgroud)
并打开一个名为“_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)
Run Code Online (Sandbox Code Playgroud)
我该如何修复它?
小智 2
我在一个名为“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'
Run Code Online (Sandbox Code Playgroud)
我可以运行代码,但不能调试它。然后我在链接中找到了一个讨论,其中的想法是代码中的模块隐藏了调试器所需的一些顶级包。我重命名了“tokenizer”模块,并且可以再次进行调试。这似乎是秘诀:尝试重命名错误输出中提到的模块。
| 归档时间: |
|
| 查看次数: |
3933 次 |
| 最近记录: |