Importerror: No Module Named 'Pysqlite2'

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

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 ".\Anaconda\Dlls\". I solved it by simply copying that .dll file from \Anaconda3\Library\bin and put it under the path mentioned above. This was life saviour.

Thanks,
Darsan

ImportError: No module named 'pysqlite2' when running tests in Python 3 Ubuntu

You are missing the sqlite3 Python module, which you can verify with:

bin/python -c 'import sqlite3'

The which sqlite3 command only shows you have the sqlite3 command line tool installed; this is not what Python uses. It uses the libsqlite3 shared library (which the command line tool also uses). If missing, it means Python was not able to find the SQLite development headers when you built Python.

On Ubuntu, you need to install libsqlite3-dev to get those headers.

You may be missing other dependencies; on Ubuntu I'd install:

libreadline6-dev
libbz2-dev
libssl-dev
libsqlite3-dev
libncursesw5-dev
libffi-dev
libdb-dev
libexpat1-dev
zlib1g-dev
liblzma-dev
libgdbm-dev
libmpdec-dev

Some of these are accelerator packages; Python will work without them but some modules will be slower (e.g. decimal without the mpdecimal library).

You may want to verify the Ubuntu Python 3.4 source package dependencies for your Ubuntu version.

ImportError: No module named pysqlite2

The module is called sqlite3. pysqlite2 was the module's name before it became part of the Python standard library.

You probably want to use this in your code:

import sqlite3

And the standard documentation is here: http://docs.python.org/library/sqlite3.html

edit: And just to cover all the bases:

The sqlite3 module also has a dbapi2 sub-member, but you don't need to use it directly. The sqlite3 module exposes all the dbapi2 members directly.

Jupyter missing _sqlite3 and pysqlite2

I was missing libsqlite3-dev when building Python3.
So after running sudo apt-get install libsqlite3-dev and rebuilding Python3 everything seems to work now.

Python 2.7 ImportError: No module named pysqlite2

Correct Answer

The right answer is that your code is old and it needs to be updated. Do that. Branch or fork the repository, do whatever it takes to get working, modern code.


You Can't Do The Right Thing™

If you are unable or unwilling to do such things for contrived reasons you have a few options, ranging from the least horrible to the most horrible:

  • Create your own pysqlite2 module, that is a wrapper around sqlite3. You'll probably only have to adapt a few functions, and you may not even have to do that. It might just look like this:

    import sqlite3

    connect = sqlite3.connect

    I'm not sure what features the code uses. But this would work, if you do it right.

  • Change the original code through monkeypatching. This is gnarly and error prone, and difficult to get right.

  • Change the original code by doing some AST hacks. This is difficult and hackish. You can do it. But you shouldn't. You really really shouldn't.

Just do the right thing, but if you can't, it is possible, with possibly a lot of effort, to do the wrong thing and make it work anyway. Just make sure to leave loads of comments apologizing profusely to the poor developer who comes after you and has to maintain this ball of duct tape and baling wire.

You never know, they may be a homicidal psychopath who knows where you live. (I know I'd get a little homicidal if I had to maintain code like this)

Python: SQLAlchemy ImportError: No module named pysqlite2

For anyone else who may have a similar problem: What are sqlite development headers and how to install them?



Related Topics



Leave a reply



Submit