76

I am trying to do the following in Python 3.7.1 on Windows

import sqlite3

but I get the following error message

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "c:\programdata\anaconda3\lib\sqlite3\__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "c:\programdata\anaconda3\lib\sqlite3\dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ImportError: DLL load failed: The specified module could not be found.

I have searched for a solution to the problem for quite a while now to no avail. I have also successfully run pip install pysqlite3 on the Anaconda prompt, but the import still fails. What do?

Jesuisme
  • 1,805
  • 1
  • 31
  • 41
G L
  • 833
  • 1
  • 6
  • 10

11 Answers11

179

I got this working on windows by downloading: the sqlite3 dll (find your system version)

And placing it into the folder: C:\Users\YOURUSER\Anaconda3\DLLs

(Depending on how you installed Anaconda, this may have to be placed into the following folder: C:\ProgramData\Anaconda3\DLLs)

According to @alireza-taghdisian, you can locate the exact path of your conda environments (where you need to copy the sqlite3 dll) by typing: conda info --envs on your anaconda prompt.

elgsantos
  • 1,993
  • 1
  • 5
  • 10
  • 18
    Also, you have to copy the file into the DLL folder that is inside of your environment folder if you are using a conda virtual environment – Jesuisme Jun 27 '19 at 20:13
  • 7
    Worked for me. But the path to my folder is: C:\Users\YOURUSER\AppData\Local\Continuum\anaconda3\DLLs – Tony P Sep 11 '19 at 13:48
  • 6
    Worked for me. Problem occured running Python 3.7.1 in VS Code. I put the sqlite3.dll (site suggested by elgsantos) in the *anaconda/envs/* that I was running python.exe. – user3730972 Dec 30 '19 at 01:36
  • I'm using virtualenv created by anaoncda on Windows. Putting sqlite3.dll in the anaconda\DLLs folders doesn't work, however, when I put it into virtualenv's scripts folders, the problem is solved. – CameLion May 26 '20 at 01:23
  • 1
    But I already have an `_sqlite.pyd` file in that folder. That's good enough for command line python in the same virtual environment. Why isn't it good enough for Anaconda when both share the same `~\Anaconda3\DLLs` folder in `sys.path`? – Jake Stevens-Haas Aug 28 '20 at 01:56
  • This worked for me too, thanks saved lot of time. It initially gave " from pysqlite2 import dbapi2 as sqlite3 ModuleNotFoundError: No module named 'pysqlite2'" 'sessionmanager.py' had problem could not import sqlite3 and was falling back on by this script "try: import sqlite3 except ImportError: # fallback on pysqlite2 if Python was build without sqlite from pysqlite2 import dbapi2 as sqlite3 " Good Catch :) – Suhail Abdul Rehman Chougule Dec 03 '20 at 05:43
  • Just in case if you have the problem with virtual env, download the file and put it in the `venv\Scripts\` directory and thanks – Peko Chan Jan 26 '22 at 09:58
  • I had this problem with VS Code and Miniconda3. I had to copy `sqlite3.dll` _and_ `sqlite3.def` that came in the Windows sqlite download package to `~/.conda/envs//DLLs`. And then it worked. Yippee – Whiz Jul 09 '22 at 04:18
22

Locate the sqlite3.dll file. In my case it was in following folder

C:\Users\Admin\anaconda3\Library\bin 

where C:\Users\Admin\anaconda3 is the folder where Anaconda was installed

Add this to PATH in environment variables, and it should work then.

user3046442
  • 468
  • 5
  • 12
  • How do I add to the PATH variable? In VS code. – guyguyguy12345 Jun 22 '21 at 18:02
  • In Pycharm you can add a PATH environment variabele under Run->Edit Configurations->Environment Variables. The benefit of this is that you can specify different paths for different python versions – Eelco van Vliet Jul 28 '21 at 07:20
  • This worked for me. Thanks. So probably a combination of elgsantos' answer if you don't already have the dll, and this one where you would add it to the PATH, is the complete answer. – Denis Sep 22 '21 at 07:52
  • For me, the folder was C:\ProgramData\Anaconda3\Library\bin – AlexM May 20 '22 at 16:15
14

Try copying the sqlite3.dll from the

C:\Users\YOURUSER\anaconda3\Library\bin

folder to

C:\Users\YOURUSER\Anaconda3\DLLs

  • I just reinstalled anaconda (with python3.8, 64Bit, on Win10) but there is no bin folder under ...anaconda3\Library. The sqlite3.dll is in ...anaconda3\pkgs\sqlite-3.35.4-h2bbff1b_0\Library\bin instead. Is that to be considered strange? Of course, I could create the folder ...anaconda3\Library\bin and copy the sqlite3.dll in there as a single .dll file. Would that be normal and OK? – delaflota Oct 05 '21 at 07:23
11

Please check https://github.com/jupyter/notebook/issues/4332 I added anaconda root/Library/bin to my PATH and now it works!

  • 1
    Did not help in my case or rather: that *is* already in my PATH and it still doesn't work. :-( – mmo May 21 '19 at 11:03
9

Add CONDA_DLL_SEARCH_MODIFICATION_ENABLE=1 to your environment variables.

Mabus
  • 1,418
  • 12
  • 20
5

before executing the program, enter conda activate in your shell.

barbsan
  • 3,418
  • 11
  • 21
  • 28
1

I was able to resolve this issue by putting sqlite3.dll file in the C:\Users<USERID>\AppData\Local\conda\conda\envs<ENV NAME>\DLLs.

Download sqlite3.dll file from https://www.sqlite.org/download.html or copy it from C:\ProgramData\Anaconda3\DLLs\

  • For me, the problem started after updating windows 11 after a spyder crash. This solution worked for me – VGB Jul 29 '23 at 13:55
1

I had tried all above solutions But for me and my system I got to know that I downloaded Python in C:\Python27 hence there is dll folder in python C:\Python27\DLLs I installed Sqlite3.dll in my above dll folder

May be this solution will help you because it completely depends on where do you install your python Happy coding :)

  • When you'll get 50 reputation, remember to use comments for such tips. – maciejwww Apr 14 '21 at 18:40
  • Your answer has some formatting problems. Try to improve that. Use `\`` brackets for paths and code fragments. To highlight apps' names or interface, use a **bold** (`**` brackets) or *italic* (`*` brackets) font. To start from a new line use *double space* at the end of the line - the question'll be way more clear than using *Enter* everywhere. Adding some `:` would be nice too. – maciejwww Apr 14 '21 at 18:40
0

I put the sqlite3.dll in the path folder of my Python venv and still wont work. I suspected it is a path problem.

(In my case: E:\Virtual_Env\mini_zinc\env\Scripts)

I found in my case I messed up installation in a virtual evn, somehow using an anaconda python kernel within a Python venv.

I reinstall the Python Venv and check the python version after installed Env is correct (not the Anaconda python), then proceed with Jupyter Notebook (or Juyterlab) and works fine.

r poon
  • 633
  • 7
  • 7
0

I found the @elgsantos useful. But for those who are new to Python and Conda like me, I would like to add a little bit of details.

1- I use miniconda3 for creating new environment.

2- interestingly, I got two installation path on my computer for conda: the first one (the obvious) is located on "C:\Users\taghdisian\miniconda3". The second one is on "C:\Users\taghdisian\AppData\Local\r-miniconda". The latter is the primary path that you need to copy your sqlite3 files into the envs folder. I copy them in the "C:\Users\taghdisian\AppData\Local\r-miniconda\envs\sdr3.9\DLLs" in which the sdr3.9 is one of my virtual Condo environment.

you can locate the exact path of your conda environments (where you need to copy sqlite3) by typing the conda info --envs on your anaconda prompt.

I hope this help.

rez
  • 290
  • 2
  • 12
0

got the same error while loading the jupyter notebook from other conda prompt than "base" environment. [1]: https://i.stack.imgur.com/2DW7E.png Resolved by installing sqlite package (nlpenv) C:\Users\arunk>conda install sqlite

launching *

(nlpenv) C:\Users\arunk>jupyter notebook