Reputation: 63
While importing nltk through terminal i got an error like this
[greenz@localhost hadoop]$ python
Python 2.6.6 (r266:84292, Feb 21 2013, 23:54:59)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/site-packages/nltk/__init__.py", line 73, in <module>
from internals import config_java
File "/usr/lib/python2.6/site-packages/nltk/internals.py", line 10, in <module>
import subprocess
File "/usr/lib/python2.6/subprocess.py", line 425, in <module>
import pickle
File "/usr/lib/python2.6/pickle.py", line 165, in <module>
__all__.extend([x for x in dir() if re.match("[A-Z][A-Z0-9_]+$",x)])
AttributeError: 'module' object has no attribute 'match'
>>>
Any idea to resolve this?
Upvotes: 3
Views: 1253
Reputation: 1
Hi i just solved this problem by removing .pyc files from the directory in which my code is present.
Upvotes: -1
Reputation: 526
This Problem looks like of circular dependency. Take a look at this answer attribution error. nltk has dependency on re module and for some reason re says that it needs to import nltk before getting fully loaded. re does not have an nltk dependency. I think this is happening because of some wrong re module coming in the python library path.
Try to import re directly in a new terminal and see where it is getting loaded from. you may have remove it and install the correct re module in the default location.
Upvotes: 1
Reputation: 14853
Could it be that you have an own file called 're.py' somewhere?
the re module has re.match
by default, no way that this is missing.
You can find that out via import re
and print(re.__file__)
Upvotes: 2