【发布时间】: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)
我该如何解决?
【问题讨论】:
-
我的问题可能是相关的并且可能很有用,因为它提供了一个复制粘贴示例。希望我们能尽快找到解决方案:stackoverflow.com/questions/36413623/…
-
你使用的是 64 位的 python 吗?你在使用 Continuum Analytics 的 Anaconda python 包管理器吗?我像这样解决了我的类似问题:stackoverflow.com/a/37398710/2734863
标签: python python-3.x debugging ide pycharm