Numpy import error

I have a strange error when I try to import numpy:

Traceback (most recent call last): File "/home/timo/malltul/mafet/src/mafet/core/pattern.py", line 7, in <module> import numpy as np File "/usr/lib/python2.6/dist-packages/numpy/__init__.py", line 147, in <module> import ma File "/usr/lib/python2.6/dist-packages/numpy/ma/__init__.py", line 44, in <module> import core File "/usr/lib/python2.6/dist-packages/numpy/ma/core.py", line 4850, in <module> all = _frommethod('all') File "/usr/lib/python2.6/dist-packages/numpy/ma/core.py", line 4824, in __init__ self.__doc__ = self.getdoc() File "/usr/lib/python2.6/dist-packages/numpy/ma/core.py", line 4830, in getdoc signature = self.__name__ + get_object_signature(meth) File "/usr/lib/python2.6/dist-packages/numpy/ma/core.py", line 109, in get_object_signature import inspect File "/usr/lib/python2.6/inspect.py", line 39, in <module> import tokenize File "/usr/lib/python2.6/tokenize.py", line 38, in <module> COMMENT = N_TOKENS NameError: name 'N_TOKENS' is not defined 

It seems like the reason is that my script is in my own package called core , and whenever I try to import numpy , I get an error. Import works fine elsewhere.

The only solution I got was to rename my β€œmain” package to something else. Why does it matter? Am I doing something wrong?

I am using Python2.6 on Ubuntu 10.14. The print version is 1.3.0.

EDIT: Actually renaming my package does not fix it. Renaming token.py in my package fixes it. I'm sorry for the mistake.

+2
source share
1 answer

I doubt this has anything to do with your core module or with numpy .

From the stack trace, it turns out that the problem is with the tokenize module, which is part of Python and not part of numpy . tokenize does from token import * , and then uses N_TOKENS , which is defined in token.py .

First of all, I would check that your PYTHONPATH does not have a token module:

 >>> import token >>> token.__file__ '/usr/lib/python2.6/token.pyc' 

If this picks up the above file, but you still get the problem, I would suggest reinstalling Python.

+4
source

All Articles