Search code examples
pythonpycharmanacondanltkconda

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


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.

Solution

  • 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!