簡體   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