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.
- Install anaconda on windows, you can read the article How To Install Anaconda On Linux, Windows, macOS Correctly.
- Create a python virtual environment in Anaconda, you can read the article How To Manage Anaconda Environments.
- Create an eclipse PyDev project, please read the article How To Run Python In Eclipse With PyDev.
- Run the source code in the article How To Use Python To Insert, Delete, Update, Query Data In SQLite DB Table.
- 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.
- 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.
- On the popup System window right side, you can find your Windows OS system type ( x86 or x64 ) in the System —> System type section.
- Download the SQLite DLL library file from the URL https://www.sqlite.org/download.html according to your Windows OS system type.
- Unzip the download file into a local folder, there are two files in the unzip folder sqlite3.dll and sqlite3.def.
- Open the anaconda navigator window by clicking the Windows start menu —> Anaconda3(64-bit) —> Anaconda Navigator(anaconda3).
- 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.
- 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)
- 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.
- Now you will find you can run the python source code in your eclipse PyDev project.
- 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.
Answer on point. Salute to you sir
I don’t know how I found you, but I’m glad I did.
you literally just save my life. thank you!
Awesome! Thanks for helping to fix my issue.