[英]NLTK ImportError: DLL load failed: The specified module could not be found
I am trying to import nltk to my project.我正在尝试将 nltk 导入我的项目。 I have tried installing it through many different ways and they all lead to the same outcome.
我尝试过通过许多不同的方式安装它,它们都会导致相同的结果。
I tried installing it through the lightbulb on PyCharm, I tried installing the module through the project settings, I tried installing nltk through conda -install nltk
.我尝试通过 PyCharm 上的灯泡安装它,我尝试通过项目设置安装模块,我尝试通过 conda
conda -install nltk
。 I don't understand why I get this error:我不明白为什么会出现此错误:
import nltk
nltk.download()
C:\Users\Orestis\PycharmProjects\LimeExamples\venv\Scripts\python.exe
C:/Users/Orestis/PycharmProjects/LimeExamples/hate_tweets.py
Traceback (most recent call last):
File "C:/Users/Orestis/PycharmProjects/LimeExamples/hate_tweets.py", line 1, in <module>
import nltk
File "C:\Users\Orestis\PycharmProjects\LimeExamples\venv\lib\site-packages\nltk\__init__.py", line 152, in <module>
from nltk.stem import *
File "C:\Users\Orestis\PycharmProjects\LimeExamples\venv\lib\site-packages\nltk\stem\__init__.py", line 29, in <module>
from nltk.stem.snowball import SnowballStemmer
File "C:\Users\Orestis\PycharmProjects\LimeExamples\venv\lib\site-packages\nltk\stem\snowball.py", line 32, in <module>
from nltk.corpus import stopwords
File "C:\Users\Orestis\PycharmProjects\LimeExamples\venv\lib\site-packages\nltk\corpus\__init__.py", line 66, in <module>
from nltk.corpus.reader import *
File "C:\Users\Orestis\PycharmProjects\LimeExamples\venv\lib\site-packages\nltk\corpus\reader\__init__.py", line 105, in <module>
from nltk.corpus.reader.panlex_lite import *
File "C:\Users\Orestis\PycharmProjects\LimeExamples\venv\lib\site-packages\nltk\corpus\reader\panlex_lite.py", line 15, in <module>
import sqlite3
File "C:\Users\Orestis\Anaconda3\lib\sqlite3\__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "C:\Users\Orestis\Anaconda3\lib\sqlite3\dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: DLL load failed: The specified module could not be found.
Its not a nltk
problem but rather a sqlite3
problem.它不是
nltk
问题,而是sqlite3
问题。 Error shows that the required sqlite dll file
is not found in your system.错误表明在您的系统中找不到所需的
sqlite dll file
。
A simple workaround solution would be to download the required dll file as per your system configuration windows/linux
x64 or x32
accordingly from here and place them at : Anaconda\\DLLs
directory.一个简单的解决方法是根据您的系统配置
windows/linux
x64 or x32
相应地从此处下载所需的 dll 文件,并将它们放置在: Anaconda\\DLLs
目录中。
Please make sure Anaconda\\DLLs
is added to your path variables as well.请确保
Anaconda\\DLLs
也添加到您的路径变量中。
For anyone that has the same problem in the future by following Pavel Karateev's advice I was able to solve this.对于任何在未来遇到相同问题的人,按照 Pavel Karateev 的建议,我都能解决这个问题。 I created a normal conda environment and installed all the packages through anaconda prompt by using eg conda -install nltk in the conda virtual environment I had created.
我创建了一个普通的 conda 环境,并在我创建的 conda 虚拟环境中使用例如 conda -install nltk 通过 anaconda 提示符安装了所有软件包。
From what I understand the problem was that I had created a venv with PyCharm UI using anaconda as a base which is a big mistake!据我了解,问题是我使用 anaconda 作为基础创建了一个带有 PyCharm UI 的 venv,这是一个大错误!
Even though the nltk errors are huge, SQLite plays a fair part.尽管 nltk 错误很大,但 SQLite 发挥了相当大的作用。
sqlite.dll
file might be located somewhere, so find it and place it in dlls folder. sqlite.dll
文件可能位于某处,因此找到它并将其放在 dlls 文件夹中。 If there is no such file, download and place it in. It worked for me.如果没有这样的文件,下载并放置它。它对我有用。
Other locations for the dll from Rohit's explanation that you might try: Rohit 的解释中 dll 的其他位置,您可以尝试:
C:\\Users\\MYUSERNAME\\Anaconda3\\DLLs C:\\Users\\MYUSERNAME\\Anaconda3\\DLLs
Or: C:\\ProgramData\\Anaconda3\\DLLs)或:C:\\ProgramData\\Anaconda3\\DLLs)
If you want to know which python location your script is running from run this in your script:如果您想知道您的脚本从哪个 python 位置运行,请在您的脚本中运行它:
import sys
sys.path
The easy and effective way is to download the sqlite3 dll from https://www.sqlite.org/download.html .简单有效的方法是从https://www.sqlite.org/download.html下载 sqlite3 dll。 Download the 64 or 32 bit depending on the OS and paste it on C:\\Users\\USER_NAME\\anaconda3\\DLLs.
根据操作系统下载 64 或 32 位并将其粘贴到 C:\\Users\\USER_NAME\\anaconda3\\DLLs。 It worked for me
它对我有用
The combination of answers from @user5099519 and @NIGHT_SHADE worked for me. @user5099519 和@NIGHT_SHADE 的答案组合对我有用。
Problem statement : There was no sqlite3 in the DLL folder.问题陈述:DLL文件夹中没有sqlite3。
Solution :解决方案:
> python
Python 3.7.15 (default, Nov 24 2022, 18:44:54) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
This will return a list of multiple paths.这将返回多个路径的列表。 You search for the term "DLL".
您搜索术语“DLL”。 For example, mine is 'C:\Users\username\anaconda3\envs\conda-env\DLLs'.
比如我的是'C:\Users\username\anaconda3\envs\conda-env\DLLs'。
import nltk
nltk.download('all')
You need to specified the module.您需要指定模块。 Also see How do I download NLTK data?
另请参阅如何下载 NLTK 数据?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.