繁体   English   中英

import nltk Not working in Python (nltk and numpy successfully installed, pip working)

[英]import nltk Not working in Python (nltk and numpy successfully installed, pip working)

我已经在这里解决了这个问题的许多版本,但我仍然找不到答案或弄清楚为什么import nltk在 Python 中不起作用。我有 Windows 10,我卸载并重新下载了这两个 32 位版本和 Python 的 64 位版本(目前我只安装了 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 nltk放入 Python IDLE 和 Python window 看起来像 windows 命令提示时,会发生这种情况:

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

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

如果没有别的,感谢您阅读到这里。

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

因此,您的 IDLE 使用的是 python 3.9,但您在 python 3.8 上安装了 nltk。

你可以试试

py -3.9 -m pip install nltk

从命令提示符然后尝试再次从 IDLE 导入 nltk。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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