'PyCharm debugger doesn't work

I just downloaded PyCharm community edition and every time I try to debug any Python program in PyCharm, I get this error:

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'

and a python file named "_pydec_excecfile.py" opens:

#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)

How can I fix it?



Solution 1:[1]

I had a similar situation in a project that had a file named 'tokenizer.py'. While trying to debug a different Python code in the same project (even in a different file) I got the following error output:

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'

I could run the code, but not debug it. Then I found a discussion at link, the idea there was that a module in the code shadowed some top level package required by the debugger. I renamed the 'tokenizer' module, and debugging was possible again. This seems to be the recipe: try to rename the module mentioned in the error output.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stanislav Koncebovski