【问题标题】:import nltk Not working in Python (nltk and numpy successfully installed, pip working)import nltk 在 Python 中不工作(nltk 和 numpy 成功安装,pip 工作)
【发布时间】:2021-07-08 18:25:46
【问题描述】:

我在这里遇到了这个问题的许多版本,但我仍然找不到答案或弄清楚为什么import nltk 在 Python 中不起作用。我有 Windows 10,我卸载并重新下载了 Python 的 32 位和 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 和看起来像 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,就像其他答案一样。我真的不知道是什么导致了问题,如果能提供任何帮助,我将不胜感激。

感谢您阅读本文。

【问题讨论】:

  • 在你的命令行中,你能不能像(base) C:\Users\Cathryn&gt; python一样打开python并测试import nltk而不是使用Python IDLE?
  • @aminrd 这发生在(base) C:\Users\Cathryn&gt;python Python 3.8.5 (default, Sep 4 2020, 00:03:40) [MSC v.1916 32 bit (Intel)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; import nltk &gt;&gt;&gt;
  • 如果import nltk 从命令提示符启动的python 工作,那么您的IDLE 使用的python 与您用于安装nltk 的python 不同。
  • @JustinEzequiel 我在“程序和功能”窗口中只看到一种 python,如果我卸载那个并安装另一个版本,我是否必须重新安装其他所有版本?
  • 您为什么认为“程序和功能窗口”是已安装 python 版本的权威来源?在 IDLE 中,输入 import sys 然后 print(sys.executable) 以查看 python IDLE 使用什么。或从命令提示符输入 py -0 以列出您拥有的不同版本。

标签: python python-3.x numpy pip nltk


【解决方案1】:

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

你可以试试

py -3.9 -m pip install nltk

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2013-01-08
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      • 2022-06-29
      • 1970-01-01
      • 2021-07-18
      • 2017-11-19
      • 2017-09-12
      相关资源
      最近更新 更多