我在Windows 7中的pycharm IDE中使用python 3.5.2,並且導入nltk包時遇到問題。ImportError:沒有名爲'nltk.tokenize'的模塊; 'nltk'不是包
import nltk
提供了以下錯誤:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.2.3\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs)
File "C:\Python\nltk practice.py", line 7, in <module> from nltk.tokenize import sent_tokenize, word_tokenize
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.2.3\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import module = self._system_import(name, *args, **kwargs)
ImportError: No module named 'nltk.tokenize'; 'nltk' is not a package
NLTK似乎被正確安裝。當我運行在終端下面
pip install nltk
我得到:
Requirement already satisfied (use --upgrade to upgrade): nltk in c:\users\leee\appdata\local\programs\python\python35-32\lib\site-packages
當我在終端運行PATH
,或在Python控制檯sys.path
,
C:\Users\leee\AppData\Local\Programs\Python\Python35-32\Lib\site-packages
顯示了中長名單。這就是我安裝的所有其他軟件包以及其他所有正確導入的軟件包的位置。
我現在很困惑,所有的幫助表示讚賞。
我也建議在PyCharm中使用'virtualenv'來隔離你的項目環境。我在這裏有一個答案:http://stackoverflow.com/questions/39937468/pycharm-import-error-claims-matplotlib-is-not-a-package-but-works-successful/39966670#39966670 – Marcs