简体   繁体   中英

Why can't I import nltk?

In windows with a 64 bit OS, once I installed nltk-2.0.4.win-amd64-py2.7.exe,from http://www.lfd.uci.edu/~gohlke/pythonlibs/ , for my 64 bit python, I ran 'import nltk' to get the following error!

Traceback (most recent call last):
  File "<pyshell#25>", line 1, in <module>
    import nltk
  File "C:\Python27\lib\site-packages\nltk\__init__.py", line 131, in <module>
    from inference import *
  File "C:\Python27\lib\site-packages\nltk\inference\__init__.py", line 19, in <module>
    from discourse import (ReadingCommand, CfgReadingCommand,
  File "C:\Python27\lib\site-packages\nltk\inference\discourse.py", line 54, in <module>
    from nltk.sem.glue import DrtGlue
  File "C:\Python27\lib\site-packages\nltk\sem\glue.py", line 13, in <module>
    from nltk.corpus import brown
  File "C:\Python27\lib\site-packages\nltk\corpus\__init__.py", line 70, in <module>
    from reader import *
  File "C:\Python27\lib\site-packages\nltk\corpus\reader\__init__.py", line 85, in <module>
    from nltk.corpus.reader.pl196x import *
  File "C:\Python27\lib\site-packages\nltk\corpus\reader\pl196x.py", line 11, in <module>
    from nltk import tokenize, tree
ImportError: cannot import name tokenize

Suggestions on how to fix this would be greatly appreciated. Thanks

I solve this problem as following reference link. It seems that the Python installer sometimes can't create proper registry entries in Win7 environment, users need to create them manually.

Ref link: http://www.fbagirov.com/2012/10/13/installing-nltk-for-python/

我通过使用my python安装路径的值创建环境变量“PYTHONPATH”来解决这个问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM