Reputation: 588
I am trying to import nltk to my project. 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
. 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.
Upvotes: 4
Views: 6776
Reputation: 31
The combination of answers from @user5099519 and @NIGHT_SHADE worked for me.
Problem statement: There was no sqlite3 in the DLL folder.
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". For example, mine is 'C:\Users\username\anaconda3\envs\conda-env\DLLs'.
Upvotes: 0
Reputation: 3299
Its not a nltk
problem but rather a sqlite3
problem. Error shows that the required sqlite dll file
is not found in your system.
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.
Make sure Anaconda\DLLs
is added to your path variables as well.
Upvotes: 5
Reputation: 1
The easy and effective way is to download the sqlite3 dll from https://www.sqlite.org/download.html. Download the 64 or 32 bit depending on the OS and paste it on C:\Users\USER_NAME\anaconda3\DLLs. It worked for me
Upvotes: 0
Reputation:
Other locations for the dll from Rohit's explanation that you might try:
C:\Users\MYUSERNAME\Anaconda3\DLLs
Or: C:\ProgramData\Anaconda3\DLLs)
If you want to know which python location your script is running from run this in your script:
import sys
sys.path
Upvotes: 0
Reputation: 21
Even though the nltk errors are huge, SQLite plays a fair part. sqlite.dll
file might be located somewhere, so find it and place it in dlls folder. If there is no such file, download and place it in. It worked for me.
Upvotes: 2
Reputation: 588
For anyone that has the same problem in the future by following Pavel Karateev's advice I was able to solve this. I created a normal conda environment and installed all the packages through anaconda prompt by using e.g. conda -install nltk in the conda virtual environment I had created.
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!
Upvotes: 1
Reputation: 32
import nltk
nltk.download('all')
You need to specified the module. Also see How do I download NLTK data?
Upvotes: -2