Import sqlite3 ошибка

I installed Python3.6 on ubuntu16.04 and installed sqlite3. When in python2, I can import sqlite successfully, but in python3 I got an import error. I tried many methods from Google, but it still doesn’t work. I want to know how to solve it.

Python 3.6.0 (default, Mar 13 2017, 06:38:19) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.

> import sqlite3

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/sqlite3/__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "/usr/local/lib/python3.6/sqlite3/dbapi2.py", line 27, in <module>
    from _sqlite3 import *

ModuleNotFoundError: No module named '_sqlite3'

gen_Eric's user avatar

gen_Eric

223k42 gold badges299 silver badges337 bronze badges

asked Mar 13, 2017 at 14:26

dragon's user avatar

4

sqlite3 will comes with python itself. I also get the same problem i just uninstalled the python3.6 and installed again.

uninstall existing python:

sudo apt-get remove --purge python3.6

Install python3.6:

sudo apt install -y \
  build-essential \
  checkinstall

sudo apt install -y \
  libreadline-gplv2-dev \
  libncursesw5-dev \
  libssl-dev \
  libsqlite3-dev \
  tk-dev \
  libgdbm-dev \
  libc6-dev \
  libbz2-dev

PYTHON_VERSION=3.6.0

wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz
tar xvf Python-${PYTHON_VERSION}.tar.xz
cd Python-${PYTHON_VERSION}/
./configure
sudo make altinstall

It works!

GabLeRoux's user avatar

GabLeRoux

16.7k16 gold badges63 silver badges81 bronze badges

answered Jul 18, 2018 at 13:50

Mastan Basha Shaik's user avatar

You can install python3 and sqlite by yourself.
try this.

Or you can try it as follows,

1. install sqlite3
$ wget https://www.sqlite.org/2017/sqlite-autoconf-3170000.tar.gz --no-check-certificate
$ tar zxvf sqlite-autoconf-3170000.tar.gz
$ cd sqlite-autoconf-3170000
$ ./configure --prefix=/usr/local/sqlite3 --disable-static --enable-fts5 --enable-json1 CFLAGS="-g -O2 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_RTREE=1"

2. install python3.6
$ cd Python-3.6.0 
$ LD_RUN_PATH=/usr/local/sqlite3/lib ./configure --prefix=/usr/local/python3.6 LDFLAGS="-L/usr/local/sqlite3/lib" CPPFLAGS="-I /usr/local/sqlite3/include"
$ LD_RUN_PATH=/usr/local/sqlite3/lib make
$ LD_RUN_PATH=/usr/local/sqlite3/lib make install 

answered Mar 14, 2017 at 6:30

ismtlee's user avatar

3

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.

  1. Install anaconda on windows, you can read the article How To Install Anaconda On Linux, Windows, macOS Correctly.
  2. Create a python virtual environment in Anaconda, you can read the article How To Manage Anaconda Environments.
  3. Create an eclipse PyDev project, please read the article How To Run Python In Eclipse With PyDev.
  4. Run the source code in the article How To Use Python To Insert, Delete, Update, Query Data In SQLite DB Table.
  5. 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.

  1. 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.
  2. On the popup System window right side, you can find your Windows OS system type ( x86 or x64 ) in the System —> System type section.
  3. Download the SQLite DLL library file from the URL https://www.sqlite.org/download.html according to your Windows OS system type.
  4. Unzip the download file into a local folder, there are two files in the unzip folder sqlite3.dll and sqlite3.def.
  5. Open the anaconda navigator window by clicking the Windows start menu —> Anaconda3(64-bit) —> Anaconda Navigator(anaconda3).
  6. 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.
  7. 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)
  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.
  9. Now you will find you can run the python source code in your eclipse PyDev project.
  10. 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.

Environment data

  • VS Code version: 1.47.3

  • Extension version (available under the Extensions sidebar): v2020.7.96456

  • OS and version: OS Name Microsoft Windows 10 Pro
    Version 10.0.19041 Build 19041

  • Python version (& distribution if applicable, e.g. Anaconda):Version 10.0.19041 Build 19041

  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): NA

  • Relevant/affected Python packages and their versions: SQLite3

  • Relevant/affected Python-related VS Code extensions and their versions: Python

  • Value of the python.languageServer setting: tht13.python

Steps to reproduce:

create file with the following contents
import sqlite3
print(sqlite3.version)
ran the file and received the following error:
File «c:\Users\howar\Google Drive\PythonCode\database\sqlite3.py», line 1, in
import sqlite3
File «c:\Users\howar\Google Drive\PythonCode\database\sqlite3.py», line 2, in
print(sqlite3.version)
AttributeError: partially initialized module ‘sqlite3’ has no attribute ‘version’ (most likely due to a circular import)

I then did a python command ‘dir(sqlite3)’ on the debug console and received the following:

dir(sqlite3)
[‘builtins‘, ‘cached‘, ‘doc‘, ‘file‘, ‘loader‘, ‘name‘, ‘package‘, ‘spec‘, ‘sqlite3’]

where it should be:

Python 3.8.4 (tags/v3.8.4:dfa645a, Jul 13 2020, 16:46:45) [MSC v.1924 64 bit (AMD64)] on win32
Type «help», «copyright», «credits» or «license» for more information.

import sqlite3
dir (sqlite3)
[‘Binary’, ‘Connection’, ‘Cursor’, ‘DataError’, ‘DatabaseError’, ‘Date’, ‘DateFromTicks’, ‘Error’, ‘IntegrityError’, ‘InterfaceError’, ‘InternalError’, ‘NotSupportedError’, ‘OperationalError’, ‘OptimizedUnicode’, ‘PARSE_COLNAMES’, ‘PARSE_DECLTYPES’, ‘PrepareProtocol’, ‘ProgrammingError’, ‘Row’, ‘SQLITE_ALTER_TABLE’, ‘SQLITE_ANALYZE’, ‘SQLITE_ATTACH’, ‘SQLITE_CREATE_INDEX’, ‘SQLITE_CREATE_TABLE’, ‘SQLITE_CREATE_TEMP_INDEX’, ‘SQLITE_CREATE_TEMP_TABLE’, ‘SQLITE_CREATE_TEMP_TRIGGER’, ‘SQLITE_CREATE_TEMP_VIEW’, ‘SQLITE_CREATE_TRIGGER’, ‘SQLITE_CREATE_VIEW’, ‘SQLITE_CREATE_VTABLE’, ‘SQLITE_DELETE’, ‘SQLITE_DENY’, ‘SQLITE_DETACH’, ‘SQLITE_DONE’, ‘SQLITE_DROP_INDEX’, ‘SQLITE_DROP_TABLE’, ‘SQLITE_DROP_TEMP_INDEX’, ‘SQLITE_DROP_TEMP_TABLE’, ‘SQLITE_DROP_TEMP_TRIGGER’, ‘SQLITE_DROP_TEMP_VIEW’, ‘SQLITE_DROP_TRIGGER’, ‘SQLITE_DROP_VIEW’, ‘SQLITE_DROP_VTABLE’, ‘SQLITE_FUNCTION’, ‘SQLITE_IGNORE’, ‘SQLITE_INSERT’, ‘SQLITE_OK’, ‘SQLITE_PRAGMA’, ‘SQLITE_READ’, ‘SQLITE_RECURSIVE’, ‘SQLITE_REINDEX’, ‘SQLITE_SAVEPOINT’, ‘SQLITE_SELECT’, ‘SQLITE_TRANSACTION’, ‘SQLITE_UPDATE’, ‘Time’, ‘TimeFromTicks’, ‘Timestamp’, ‘TimestampFromTicks’, ‘Warning’, ‘builtins‘, ‘cached‘, ‘doc‘, ‘file‘, ‘loader‘, ‘name‘, ‘package‘, ‘path‘, ‘spec‘, ‘adapt’, ‘adapters’, ‘apilevel’, ‘collections’, ‘complete_statement’, ‘connect’, ‘converters’, ‘datetime’, ‘dbapi2’, ‘enable_callback_tracebacks’, ‘enable_shared_cache’, ‘paramstyle’, ‘register_adapter’, ‘register_converter’, ‘sqlite_version’, ‘sqlite_version_info’, ‘threadsafety’, ‘time’, ‘version’, ‘version_info’]>>>

XXX

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

  1. XXX

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

Download python 3.3.2 http://www.python.org/getit/

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

What are the packages/libraries I should install before compiling Python from source?
https://askubuntu.com/questions/21547/what-are-the-packages-libraries-i-should-install-before-compiling-python-from-so

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

Python is a versatile language with a wide range of libraries and modules. However, sometimes, you may encounter issues while importing certain modules. One such common issue is the inability to import sqlite3 using Anaconda Python. This blog post will guide you through the process of resolving this issue.

Solving the Issue: Unable to Import sqlite3 Using Anaconda Python

Python is a versatile language with a wide range of libraries and modules. However, sometimes, you may encounter issues while importing certain modules. One such common issue is the inability to import sqlite3 using Anaconda Python. This blog post will guide you through the process of resolving this issue.

Introduction

SQLite is a C library that provides a lightweight disk-based database. It doesn’t require a separate server process and allows accessing the database using a nonstandard variant of the SQL query language. Some applications can use SQLite for internal data storage. It’s also possible to prototype an application using SQLite and then port the code to a larger system.

Anaconda, on the other hand, is a free and open-source distribution of the Python and R programming languages for scientific computing, that aims to simplify package management and deployment.

However, sometimes, when you try to import sqlite3 in your Python script using Anaconda, you might encounter an error. This blog post will help you understand why this happens and how to fix it.

Understanding the Issue

Before we dive into the solution, let’s understand why this issue occurs. The main reason behind this error is that the sqlite3 module is not installed in your Anaconda environment. This could be because the environment you’re working in doesn’t have access to the sqlite3 module, or because the module itself is not installed.

Steps to Resolve the Issue

Here’s a step-by-step guide to help you resolve the issue:

Step 1: Check Your Environment

First, check if you’re working in the correct environment. If you’re working in an Anaconda environment, make sure that the sqlite3 module is installed in that environment. You can check this by running the following command in your Anaconda prompt:

If sqlite3 is installed, it should appear in the list of packages. If it doesn’t, you need to install it.

Step 2: Install sqlite3

To install sqlite3, you can use the following command in your Anaconda prompt:

conda install -c anaconda sqlite

This command will install sqlite3 in your current Anaconda environment.

Step 3: Verify the Installation

After the installation is complete, you can verify it by importing sqlite3 in your Python script. If the module is imported successfully, the issue is resolved.

Conclusion

In this blog post, we discussed the issue of being unable to import sqlite3 using Anaconda Python and provided a step-by-step guide to resolve it. By following these steps, you should be able to successfully import sqlite3 in your Python script using Anaconda.

Remember, the key to resolving such issues is understanding the cause. Once you understand why the issue is occurring, you can take the necessary steps to resolve it.

We hope this blog post was helpful. If you have any questions or need further assistance, feel free to reach out.

Keywords

  • sqlite3
  • Anaconda Python
  • Import Error
  • Python Script
  • Module Installation
  • Anaconda Environment
  • Package Management
  • Scientific Computing
  • SQL Query Language
  • Disk-based Database

Are you unable to import sqlite3 using Anaconda Python? This blog post provides a step-by-step guide to help you resolve this issue. Learn how to check your environment, install sqlite3, and verify the installation.


About Saturn Cloud

Saturn Cloud is your all-in-one solution for data science & ML development, deployment, and data pipelines in the cloud. Spin up a notebook with 4TB of RAM, add a GPU, connect to a distributed cluster of workers, and more. Join today and get 150 hours of free compute per month.

Понравилась статья? Поделить с друзьями:
  • Illegal new face 3d max ошибка
  • Import seaborn as sns ошибка
  • Immobilizer see manual volvo xc90 как сбросить ошибку
  • Iis журнал ошибок
  • Import requests python ошибка