Running Jupyter Notebook from cmd raises ModuleNotFoundError: No module named pysqlite2

Question:

The problem:

After reinstalling Anaconda I can no longer navigate to a folder using the command window where I’ve got some .pynb files, type jupyter notebook and get things up and running. I’m getting these errors:

C:scriptsnotebooks>jupyter notebook Traceback (most recent call
last): File
“C:UsersMYUSERIDAppDataLocalContinuumanaconda3libsite-packagesnotebookservicessessionssessionmanager.py”,
line 10, in
import sqlite3 File “C:UsersMYUSERIDAppDataLocalContinuumanaconda3libsqlite3__init__.py”,
line 23, in
from sqlite3.dbapi2 import * File “C:UsersMYUSERIDAppDataLocalContinuumanaconda3libsqlite3dbapi2.py”,
line 27, in
from _sqlite3 import * ImportError: DLL load failed: Procedyre not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File
“C:UsersMYUSERIDAppDataLocalContinuumanaconda3Scriptsjupyter-notebook-script.py”,
line 6, in
from notebook.notebookapp import main File “C:UsersMYUSERIDAppDataLocalContinuumanaconda3libsite-packagesnotebooknotebookapp.py”,
line 86, in
from .services.sessions.sessionmanager import SessionManager File
“C:UsersMYUSERIDAppDataLocalContinuumanaconda3libsite-packagesnotebookservicessessionssessionmanager.py”,
line 13, in
from pysqlite2 import dbapi2 as sqlite3 ModuleNotFoundError: No module named ‘pysqlite2’


What I’ve tried:


I’ve checked the fresh Anaconda folders, and everything seems to be where it should wrt sqlite, sqlite3 and pysqlite2.

Since last time I downloaded Anaconda, it seems they’ve changed the default install folders, so I was sure everything would be OK after editing my user and system environment variables according to the post Jupyter notebook will not open from command prompt just in case checking the Add to Path option upon reinstalling Anaconda was not enough. But I’m still getting the same error messages.

When I launch Jupyter from the Anaconda Navigator, everything runs fine.

A similar question has been asked, but not answered, for Ubuntu here: 2x ModuleNotFoundError Jupyter notebook


Edit:


When I use and Anaconda Prompt, jupyter also starts running just fine when entering jupyter notebook. So why bother with the command window? The anaconda prompt command does not open ipynb files automatically in the deafault web browser. My earlier setup with the windows command window (and a batch file) did that and I think it was very useful.


System details:

Windows 7, 64 bit
Anaconda 2018.12
Jupyter Notebook 5.7.4
Python 3.7.1
IPython 7.2.0
Asked By: vestland

||

Answers:

Short answer:

This appears to be a version issue as of 29.01.2019 only related to:

Anaconda3-2018.12-Windows-x86_64:

Jupyter Notebook 5.7.4
Python 3.7.1 (default, Dec 10 2018, 22:54:23) 
IPython 7.2.0

Check the list in the details below to see versions that will not raise the ModuleNotFoundError: No module named pysqlite2 when launching Jupyter from batch, or even trying to install nbExtensions.

For version Anaconda3-2018.12, Jupyter can be launched from batch using the setup from GokulDAS027 in this post, but it will not open automatically in your default web browser. You can also launch Jupyter from the Anaconda Navigator without problems.

The details:


Solution 1: Run more detailed batch


It turns out that the suggestion from GokulDAS027 to the question Using a .bat to change directories and run Jupyter for some reason will open Jupyter without raising the sqlite error messages:

C:Users**UserName**Anaconda3python.exe C:Users**UserName**Anaconda3cwp.py C:Users**UserName**Anaconda3 C:Users**UserName**Anaconda3python.exe C:Users**UserName**Anaconda3Scriptsjupyter-notebook-script.py "**file location**"

On my system, Jupyter will not automatically open the default web-browser though.
Also, if you’d like to install Notebook Extensions, you’ll get a related error message. Since I did not find this very satisfactory, I started some more digging on whether or not this is a problem for later versions of Anaconda as well:


Solution 2: Install older versions of Anaconda


I noticed some comments on github that pysqlite2 is not used in Python 3. I was pretty certain that I did not have the ModuleNotFoundError: No module named pysqlite2 about a year ago when I was already using Python 3, so I tested a few older Anaconda installations to check whether or not the same error would be raised.

It appears that the pysqlite2 error will only be raised for the very latest version (per 29.01.2019):

Anaconda3-2018.12

Jupyter Notebook 5.7.4
Python 3.7.1 (default, Dec 10 2018, 22:54:23) 
IPython 7.2.0

With the system setups described below (still on Windows 7, 64 bit) everything runs fine, meaning:

  1. Jupyter can be started from a command prompt (not only Anaconda prompt) by navigating to a folder and typing jupyter notebook, and it’s launched automatically in the default web browser.

  2. nbExtensions can be installed using conda install -c conda-forge jupyter_contrib_nbextensions

Tested versions from Anaconda Archive

Anaconda3-5.3.1

Jupyter Notebook 5.6.0
Python 3.7.0 (default, Jun 28 2018, 08:04:48) [MSC v.1912 64 bit (AMD64)]
IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.

Anaconda3-4.4.0

Python 3.6.1 |Anaconda 4.4.0 (64-bit)|
IPython 5.3.0

Anaconda2-4.3.1-Windows-x86_64

Jupyter Notebook 4.3.1
Python 2.7.13 |Anaconda 4.3.1 (64-bit)| 
IPython 5.1.0 
Answered By: vestland

if you have oracle client installed for cx_Oracle package please check if you have /usr/lib in the DYLD_LIBRARY_PATH. Try removing /usr/bin from the path and see if it works.

I had the same problem and this worked for me. I have tried it on MacOS.

Answered By: Elf

This answer is for users who might have compiled Python from source and also for the users who dont have admin rights (as a result I cant use Homebrew). I faced the same error but my python environment is customised and I am not using anaconda or pyenv. A side note, my OS is macOS mojave 10.14.6.

I recompiled and reconfigured sqlite manually from source package. Steps:

  1. Download sqlite tarfile from this page.
  2. Navigate to the /path/to/python_dir/Python-3.x.x/Modules where your Python version is installed. (Because I am not the admin I installed it here : /Users/myusername/python3. ) : /Users/myusername/python3/Python-3.6.8/Modules/
  3. Extract sqlite under /Modules/: tar zxf /Users/myusername/Downloads/sqlite.tar.gz
  4. cd sqlite
  5. configure sqlite locally : ./configure --prefix='/Users/myusername/python3'
    side note: without the prefix option make install will install files in default location. check this answer. So use the prefix option if your python is not at default location.
  6. make && make install
  7. go back to python folder and reconfigure python binaries, and point to sqlite :
    cd ../../ and then:
    ./configure --prefix='/Users/myusername/python3' --with-sqlite='/Users/myusername/python3'.
  8. make && make install

Side note : It turns out that if you configured Python manually and you can’t install some library using pip probably you have to configure and recompile that package from source. Download the tar file of your package and repeat the above steps for your package. I also had problems with zlib and openssl and i did the same as above.
Some other threads you might find useful : this , maybe this also

Answered By: Siddhant Tandon

I was stuck on the same issue for like a day. finally found the solution its working now.

The issue seems to arise from the missing of sqlite3.dll in path “.AnacondaDlls”. I solved it by simply copying that .dll file from Anaconda3Librarybin and put it under the path mentioned above. This was life saviour.

Thanks,
Darsan

Answered By: Darsan
  1. from this link to download pysqlite: https://www.sqlite.org/download.html

  2. zip the file to the dir:(anaconda3DLLs)

Answered By: yuanzz

This worked for me on Windows 10:

Replace the file “C:WindowsSystem32sqlite3.dll” with “C:Usersusernameanaconda3Librarybinsqlite3.dll”

Answered By: George Hernando