Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NameError: name 'N_TOKENS' is not defined

I am new on Python and just got around to install PyCharm for Windows. Downloaded some sample code from Skype for testing their SkypeKit API. But... As soon as I hit the debug button, I get this: (I have Python 2.7 and Django 1.4 installed)

Traceback (most recent call last):
  File "C:\Program Files (x86)\JetBrains\PyCharm 2.0.2\helpers\pydev\pydevd.py", line 2, in <module>
    from django_debug import DjangoLineBreakpoint
  File "C:\Program Files (x86)\JetBrains\PyCharm 2.0.2\helpers\pydev\django_debug.py", line 1, in <module>
    import inspect
  File "C:\Program Files (x86)\Python27\lib\inspect.py", line 39, in <module>
    import tokenize
  File "C:\Program Files (x86)\Python27\lib\tokenize.py", line 38, in <module>
    COMMENT = N_TOKENS
NameError: name 'N_TOKENS' is not defined

Process finished with exit code 1

What does this mean and what can I do to fix it?

like image 792
BlueVoodoo Avatar asked Apr 08 '12 22:04

BlueVoodoo


People also ask

How do you solve NameError name is not defined?

The Python "NameError: name is not defined" occurs when we try to access a variable or function that is not defined or before it is defined. To solve the error, make sure you haven't misspelled the variable's name and access it after it has been declared.

Why am I getting a NameError in Python?

In Python, the NameError occurs when you try to use a variable, function, or module that doesn't exist or wasn't used in a valid way. Some of the common mistakes that cause this error are: Using a variable or function name that is yet to be defined.

What does a NameError mean?

NameError is a kind of error in python that occurs when executing a function, variable, library or string without quotes that have been typed in the code without any previous Declaration. When the interpreter, upon execution, cannot identify the global or a local name, it throws a NameError.


1 Answers

The tokenize.py module is probably loading the wrong token.py module. See error importing numpy. Solution 1) rename the new token.py (token2.py) and update references to it in tokenize.py etc. Solution 2) if the new token.py is in a python package you can disambiguate the import statement:

import CorrectPythonPackage.token as token2

#or 

from CorrectPythonPackage.token import *

Where CorrectPythonPackage is the folder name containing the token.py file.

like image 99
Riaz Rizvi Avatar answered Sep 29 '22 20:09

Riaz Rizvi