- ModuleNotFoundError: No module named ‘_sqlite3’
- 4 Answers 4
- Python 3.2: can’t import sqlite3 module
- 4 Answers 4
- How to install sqlite3 for python3.7 in seperate directory on linux without sudo commands?
- 2 Answers 2
- Modulenotfounderror: no module named _sqlite3 ( Solved )
- What is ModuleNotFoundError?
- Why does the Modulenotfounderror: no module named ‘_sqlite3’ occurs ?
- Solution of the no module named ‘_sqlite3’ Error
- Conclusion
ModuleNotFoundError: No module named ‘_sqlite3’
On Redhat 4.4.7-18 I am trying to run python3 code using sqlite, but I get the following import error:
Traceback (most recent call last): File "database.py", line 7, in import sqlite3 File "/usr/local/lib/python3.6/sqlite3/__init__.py", line 23, in from sqlite3.dbapi2 import * File "/usr/local/lib/python3.6/sqlite3/dbapi2.py", line 27, in from _sqlite3 import * ModuleNotFoundError: No module named '_sqlite3'
>sudo pip install sqlite3 Collecting sqlite3 Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', error(101, 'Network is unreachable'))': /simple/sqlite3/
> sudo yum install sqlite-devel Loaded plugins: post-transaction-actions, product-id, refresh-packagekit, : rhnplugin, search-disabled-repos, security, subscription-manager This system is receiving updates from RHN Classic or RHN Satellite. Setting up Install Process Package sqlite-devel-3.6.20-1.el6_7.2.x86_64 already installed and latest version Nothing to do
sqlite3 is an optional module in the standard library, and it wasn’t compiled for your platform. How did you install Python? If you compiled from source you need to have the sqlite development headers available for the module to be compiled.
Is there a page describing to check if I have the headers, how to install the headers, how and where to compile sqlite?
I did ask how you installed Python. The ./configure script has a —help option that details all the different things it’ll look for and how to tell it to look elsewhere. If you didn’t compile Python on a machine with the SQLite headers in a standard location the _sqlite3 C module is never compiled, that’s all I can tell you, so I gave the standard responses.
4 Answers 4
Not a direct answer but I ended up here with my search engine. So for my fellow web-surfers:
I had a similar issue, but on ubuntu 16.04 with a manually compile python3.6 version :
from _sqlite3 import * ModuleNotFoundError: No module named '_sqlite3'
I had to install libsqlite3-dev ( sudo apt install libsqlite3-dev ) and compile from the start python3.6 to make it work.
See the linked answer for re-compiling a pyenv env following the instructions in the answer: stackoverflow.com/questions/56994638/…
Does that mean I have to re-compile Python after installing the module? My Python is installed via tools, not download and build on my own. What should I do?
sudo yum install sqlite-devel
Followed by rebuild of Python 3.8.3 from source did the trick. Thx!
I had this issue on linux mint 20 after sqlite3 successfully installed
from _sqlite3 import * ModuleNotFoundError: No module named '_sqlite3'
also, could not import sqlite3 into python interpreter
sudo apt install libsqlite3-dev
cd your python installer directory
./configure sudo make install
for me worked as you said adding: ./configure —enable-loadable-sqlite-extensions —enable-optimizations
It happens when you install Python using the source code and then compile. Usually people tend to install python and sqlite into separate folders. This causes sqlite binary inaccessible to python executables.
To solve this problem, use a common folder to install BOTH, the Python as well as sqlite. So that python binary and sqlite binary, reside in the same bin folder.
Below example script will solve:
INSTALL_BASE_PATH="/home//" cd ~ mkdir build cd build [ -f Python-3.9.10.tgz ] || wget --no-check-certificate https://www.python.org/ftp/python/3.9.10/Python-3.9.10.tgz tar -zxvf Python-3.9.10.tgz [ -f sqlite-autoconf-3380000.tar.gz ] || wget --no-check-certificate https://www.sqlite.org/2022/sqlite-autoconf-3380000.tar.gz tar -zxvf sqlite-autoconf-3380000.tar.gz cd sqlite-autoconf-3380000 ./configure --prefix=$ make make install cd ../Python-3.9.10 LD_RUN_PATH=$/lib configure LDFLAGS="-L $/lib" CPPFLAGS="-I $/include" LD_RUN_PATH=$/lib make ./configure --prefix=$ make make install cd ~ LINE_TO_ADD="export PATH=$/bin:\$PATH" if grep -q -v "$" $HOME/.bashrc; then echo "$" >> $HOME/.bashrc; fi LINE_TO_ADD="export LD_LIBRARY_PATH=$/lib" if grep -q -v "$" $HOME/.bashrc; then echo "$" >> $HOME/.bashrc; fi source $HOME/.bashrc
Python 3.2: can’t import sqlite3 module
I’ve just installed python 3.2.2 on ubuntu 10.04.3 (following all instraction from readme file) and tried to import sqlite3 module — the result:
Then I’ve looked into lib-dynload directory and there is no file _sqlite3.so (but it is in python 2.6). How to fix this problem? Thanks!
There is probably different package for Python 3 SQlite. Python 2 and Python 3 libraries are incompatible.
4 Answers 4
If you installed from source, you need to install the development libraries for sqlite3.
sudo apt-get install libsqlite3-dev
You probably also want to install libreadline-dev and libssl-dev .
@LennartRegebro: In this case, the development libraries for sqlite3 (and other modules like readline, ssl, etc.) need to be installed before compiling Python from source. The C source code for the Python sqlite module is included with Python’s source; however it requires the presence of sqlite3’s development file to compile. It is not a separate library but part of Python.
The development libraries for sqlite3 (and other modules like readline, ssl, etc.) need to be installed before compiling Python from source. The C source code for the Python sqlite module is included with Python’s source; however it requires the presence of sqlite3’s development file to compile. It is not a separate library but part of Python.
If you installed from source, you need to install the development libraries for sqlite3.
sudo apt-get install libsqlite3-dev
sudo apt-get install libreadline-dev sudo apt-get install libssl-dev
List of common dev environments .
build-essential (obviously) libz-dev (also pretty common and essential) libreadline-dev (or the Python prompt is crap) libncursesw5-dev libssl-dev libgdbm-dev libsqlite3-dev libbz2-dev liblzma-dev tk-dev libdb-dev libncursesw5-dev libreadline5-dev libssl-dev libgdbm-dev libc6-dev
Install Python
tar xf Python-3.3.2.tar.xz ./configure make sudo make all install
How to install sqlite3 for python3.7 in seperate directory on linux without sudo commands?
I have the problem that when I run my code on a linux server I get: ModuleNotFoundError: No module named ‘_sqlite3’ So after researching, I found out sqlite3 was supposed to have been installed when I installed python, however it didn’t. I think the problem comes from the way I installed python. Since I do not have sudo permissions, I installed python3.7 in a local directory using: This guide. All solutions to this sqlite3 problem that I can find requires sudo commands. Is there another way that I can install python3.7 together with sqlite3 in my local Linux directory without using any sudo commands? I hope I have stated my question clearly and I would appreciate all the help I can get. Thank you!
I don’t think the code is really important. The problem is that I don’t have sqlite3 module. My code uses the openmdao module which happens to use the sqlite3 module.
I did try that, installing pysqlite works, but I still get the same error message: No module named ‘_sqlite3’
2 Answers 2
While installing a python package in a Linux system without «sudo» privileges you can use
pip3 install —user pysqlite3
You can install any third party packages with the same method
pip3 install —user PACKAGE_NAME
The —user flag to pip install tells Pip to install packages in some specific directories within your home directory. For more information click here.
Hope it helps !
The solution is to first build sqlite3 into a user directory and then build python using that directory’s libraries and include headers. In particular, @Ski has answered a similar question regarding python 2, which can be adopted to python 3:
$ mkdir -p ~/applications/src $ cd ~/applications/src $ # Download and build sqlite 3 (you might want to get a newer version) $ wget http://www.sqlite.org/sqlite-autoconf-3070900.tar.gz $ tar xvvf sqlite-autoconf-3070900.tar.gz $ cd sqlite-autoconf-3070900 $ ./configure --prefix=~/applications $ make $ make install $ # Now download and build python 2, same works for python 3 $ cd ~/applications/src $ wget http://www.python.org/ftp/python/2.5.2/Python-2.5.2.tgz $ tar xvvf Python-2.5.2.tgz $ cd Python-2.5.2 $ ./configure --prefix=~/applications $ make $ make install $ ~/applications/bin/python
Alternatively, if you already have to specify a different —prefix for some reason (this has happened to me with pyenv ), use LDFLAGS and CPPFLAGS when configuring python build:
$ ./configure LDFLAGS=-L/home/user/applications/lib/ CPPFLAGS=-I/home/user/applications/include/
Modulenotfounderror: no module named _sqlite3 ( Solved )
SQLite3 is a lightweight database engine that is available as a part of the Python Standard Library. It acts as local database. Therefore makes it very fast and reliable. If you are building small applications then SQLite3 is the best framework as it is a lightweight database engine. However, sometimes you can get errors like Modulenotfounderror: no module named ‘_sqlite3’.
If you are getting then this post is for you. In this tutorial, you will learn how to solve this error.
What is ModuleNotFoundError?
The “ModuleNotFoundError” is an exception error that is raised when a Python program is unable to find a module that it requires. It can happen for a number of reasons, but the most common reason is that the module you’re trying to use simply doesn’t exist in your system. For example, if you are importing the module “x” then you will get the error Modulenotfounderror: no module named ‘x’ if the python interpreter does not find the module x in your system.
Why does the Modulenotfounderror: no module named ‘_sqlite3’ occurs ?
There can be many reasons for getting the error No module named ‘_sqlite3’ but the most common reason is that the SQLite library must not be installed on your system.
If you are a Windows user, you can download the SQLite3 library from the official website. And If you are a Mac user, you can install the SQLite library using Homebrew.
You will get the following error when you will use the SQLite module in your python code.
Modulenotfounderror: no module named '_sqlite3' occurs
Solution of the no module named ‘_sqlite3’ Error
To solve this error you have to install the db-sqlite3 module in your system. To install it you have to check the version of python. If the version of the python is 3. xx then use pip3 and if it is python 2. xx then use the pip command.
Python 3. xx
After that, if you try to use the sqlite3 code in your python code then you will not get the error.
But even If you’re still getting the “no module named ‘_sqlite3′” error, then you have to check the PYTHONPATH variable. The PYTHONPATH variable contains the list of directories that Python.
To check your PYTHONPATH variable, open your terminal window or command prompt and run the following command:
You will get the path for all the python modules installed in your system. You have to set the Python path for the sqlite3 module. Run the following command to add the
export PYTHONPATH="/usr/local/lib/python3.7/site-packages:$PYTHONPATH"
It will solve the Modulenotfounderror: no module named ‘_sqlite3’ error.
Conclusion
SQLite3 is lightweight database API that is very useful if you want to make a prototype of an application or are using small applications. If you are getting the Modulenotfounderror: no module named ‘_sqlite3’ error then the above method will solve this error.