首页 > 解决方案 > import nltk 在 Python 中不工作(nltk 和 numpy 已成功安装,pip 工作)

问题描述

我在这里遇到了这个问题的许多版本,但我仍然找不到答案或弄清楚为什么import nltk不能在 Python 中工作。我有 Windows 10,我卸载并重新下载了 32 位和 64 位版本的 Python(目前我只安装了 64 位版本),这就是我的命令提示符的样子:

(base) C:\Users\Cathryn>py -3.8-32 -m pip install -U nltk
Collecting nltk
  Downloading nltk-3.6.1-py3-none-any.whl (1.5 MB)
     |████████████████████████████████| 1.5 MB 6.8 MB/s
Requirement already satisfied, skipping upgrade: joblib in c:\users\cathryn\anaconda3\lib\site-packages (from nltk) (0.17.0)
Requirement already satisfied, skipping upgrade: tqdm in c:\users\cathryn\anaconda3\lib\site-packages (from nltk) (4.50.2)
Requirement already satisfied, skipping upgrade: regex in c:\users\cathryn\anaconda3\lib\site-packages (from nltk) (2020.10.15)
Requirement already satisfied, skipping upgrade: click in c:\users\cathryn\anaconda3\lib\site-packages (from nltk) (7.1.2)
Installing collected packages: nltk
  Attempting uninstall: nltk
    Found existing installation: nltk 3.5
    Uninstalling nltk-3.5:
      Successfully uninstalled nltk-3.5
Successfully installed nltk-3.6.1

(base) C:\Users\Cathryn>pip install nltk
Requirement already satisfied: nltk in c:\users\cathryn\anaconda3\lib\site-packages (3.6.1)
Requirement already satisfied: joblib in c:\users\cathryn\anaconda3\lib\site-packages (from nltk) (0.17.0)
Requirement already satisfied: regex in c:\users\cathryn\anaconda3\lib\site-packages (from nltk) (2020.10.15)
Requirement already satisfied: tqdm in c:\users\cathryn\anaconda3\lib\site-packages (from nltk) (4.50.2)
Requirement already satisfied: click in c:\users\cathryn\anaconda3\lib\site-packages (from nltk) (7.1.2)

(base) C:\Users\Cathryn>pip install numpy
Requirement already satisfied: numpy in c:\users\cathryn\anaconda3\lib\site-packages (1.19.2)

然而,当我放入import nltkPython IDLE 和看起来像 windows 命令提示符的 Python 窗口时,会发生这种情况:

>>> import nltk
Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    import nltk
ModuleNotFoundError: No module named 'nltk'
>>> 

我遵循了https://www.nltk.org/install.html上的所有说明,而不是使用 64 位版本而不是推荐的 32 位版本。我像其他建议的答案一样下载了 Anaconda 。我真的不知道是什么导致了这个问题,我将不胜感激。

如果没有别的,感谢您阅读本文。

标签: pythonpython-3.xnumpypipnltk

解决方案


您的编辑器可能使用了错误的解释器。它必须指向作为基础环境的“PathToAnaconda\python.exe”。


推荐阅读