NLTK ImportError: DLL load failed: The specified module could not be found

Question:

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:UsersOrestisPycharmProjectsLimeExamplesvenvScriptspython.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:UsersOrestisPycharmProjectsLimeExamplesvenvlibsite-packagesnltk__init__.py", line 152, in <module>
    from nltk.stem import *
  File "C:UsersOrestisPycharmProjectsLimeExamplesvenvlibsite-packagesnltkstem__init__.py", line 29, in <module>
    from nltk.stem.snowball import SnowballStemmer
  File "C:UsersOrestisPycharmProjectsLimeExamplesvenvlibsite-packagesnltkstemsnowball.py", line 32, in <module>
    from nltk.corpus import stopwords
  File "C:UsersOrestisPycharmProjectsLimeExamplesvenvlibsite-packagesnltkcorpus__init__.py", line 66, in <module>
    from nltk.corpus.reader import *
  File "C:UsersOrestisPycharmProjectsLimeExamplesvenvlibsite-packagesnltkcorpusreader__init__.py", line 105, in <module>
    from nltk.corpus.reader.panlex_lite import *
  File "C:UsersOrestisPycharmProjectsLimeExamplesvenvlibsite-packagesnltkcorpusreaderpanlex_lite.py", line 15, in <module>
    import sqlite3
  File "C:UsersOrestisAnaconda3libsqlite3__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "C:UsersOrestisAnaconda3libsqlite3dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ImportError: DLL load failed: The specified module could not be found.
Asked By: thelaw

||

Answers:

import nltk    
nltk.download('all')

You need to specified the module. Also see How do I download NLTK data?

Answered By: Terrillo Walls

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!

Answered By: thelaw

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: AnacondaDLLs directory.

Make sure AnacondaDLLs is added to your path variables as well.

Answered By: Rohit Lal

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.

Other locations for the dll from Rohit’s explanation that you might try:

C:UsersMYUSERNAMEAnaconda3DLLs

Or: C:ProgramDataAnaconda3DLLs)

If you want to know which python location your script is running from run this in your script:

import sys
sys.path
Answered By: user5099519

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:UsersUSER_NAMEanaconda3DLLs. It worked for me

Answered By: NIGHT_SHADE

The combination of answers from @user5099519 and @NIGHT_SHADE worked for me.

Problem statement: There was no sqlite3 in the DLL folder.

Solution:

  • Step 1: Identify where the DLL folder is. Activate your conda environment and type the following:
> 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:Usersusernameanaconda3envsconda-envDLLs’.

  • Step 2: Download sqlite3 dll from https://www.sqlite.org/download.html then extract it into the DLL folder. For example, as a 64-bit Windows user, in Precompiled Binaries for Windows, I selected sqlite-dll-win64-x64-3400000.zip.
Answered By: Hồ Xuân Vinh
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.