3

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?

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
deadendtux
  • 63
  • 2
  • 8
  • Looks like the pickle module is broken. Try reinstalling python or, even better, upgrading to 2.7 – J0HN Jun 21 '13 at 15:27

4 Answers4

2

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

User
  • 14,131
  • 2
  • 40
  • 59
1

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.

Community
  • 1
  • 1
vinit
  • 526
  • 7
  • 18
-1

Hi i just solved this problem by removing .pyc files from the directory in which my code is present.

-1

Upgrade your python from 2.6 to 2.7 or more and try again