How To Fix ImportError: DLL Load Failed While Importing _sqlite3: The Specified Module Could Not Be Found.

This article will tell you how to fix the ImportError: DLL load failed while importing _sqlite3: The specified module could not be found when you run eclipse to develop a python project through PyDev with the anaconda virtual environment. The error happens on Windows OS.

1. Reproduce the ImportError: DLL load failed while importing _sqlite3: The specified module could not be found steps.

  1. Install anaconda on windows, you can read the article How To Install Anaconda On Linux, Windows, macOS Correctly.
  2. Create a python virtual environment in Anaconda, you can read the article How To Manage Anaconda Environments.
  3. Create an eclipse PyDev project, please read the article How To Run Python In Eclipse With PyDev.
  4. Run the source code in the article How To Use Python To Insert, Delete, Update, Query Data In SQLite DB Table.
  5. When you run the example source code, the first line of code import sqlite3 will throw the below error.

    Traceback (most recent call last):
      File "C:\WorkSpace\Work\dev2qa.com-example-code\PythonExampleProject\com\dev2qa\example\sqlite\SQLiteOperationExample.py", line 8, in <module>
        import sqlite3
      File "C:\Users\zhaosong\anaconda3\envs\python_example\lib\sqlite3\__init__.py", line 23, in <module>
        from sqlite3.dbapi2 import *
      File "C:\Users\zhaosong\anaconda3\envs\python_example\lib\sqlite3\dbapi2.py", line 27, in <module>
        from _sqlite3 import *
    ImportError: DLL load failed while importing _sqlite3: The specified module could not be found.

2. How to fix the ImportError: DLL load failed while importing _sqlite3: The specified module could not be found steps.

  1. Open a windows explorer in Windows OS, right-click the This PC icon on the left side, click the Properties menu item in the popup menu list.
  2. On the popup System window right side, you can find your Windows OS system type ( x86 or x64 ) in the System —> System type section.
  3. Download the SQLite DLL library file from the URL https://www.sqlite.org/download.html according to your Windows OS system type.
  4. Unzip the download file into a local folder, there are two files in the unzip folder sqlite3.dll and sqlite3.def.
  5. Open the anaconda navigator window by clicking the Windows start menu —> Anaconda3(64-bit) —> Anaconda Navigator(anaconda3).
  6. Click the Environments menu item on the anaconda navigator popup window left side, select your python virtual environment on the center, and click the green arrow button at the end of the python virtual environment, then click the Open Terminal menu item on the popup menu list.
  7. Input command pip -V in the popup dos window, then it will return the anaconda python virtual environment installed directory path.
    (python_example) C:\Users\zhaosong>pip -V
    pip 20.2.2 from C:\Users\zhaosong\anaconda3\envs\python_example\lib\site-packages\pip (python 3.8)
  8. Copy the files sqlite3.dll and sqlite3.def to the directory C:\Users\zhaosong\anaconda3\envs\python_example\DLLs in this example. In this example, the anaconda python virtual environment name is python_example.
  9. Now you will find you can run the python source code in your eclipse PyDev project.
  10. You can also copy the sqlite3.dll and sqlite3.def to the directory C:\Users\zhaosong\anaconda3\DLLs, if you do like this, you need to add the directory path C:\Users\zhaosong\anaconda3\DLLs to the PyDev —> PYTHONPATH —> External Libraries in eclipse PyDev project properties window. You can read the article How To Add Library In Python Eclipse Project to learn more.

4 thoughts on “How To Fix ImportError: DLL Load Failed While Importing _sqlite3: The Specified Module Could Not Be Found.”

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.