2

I have created my virtual environment for a project:

python -m venv my_virtual_environment
cd my_project\Scripts
activate.bat

When the following code is executed:

import sys
print('\n Virtual environment: \n', sys.prefix)

import sqlite3

I get the following message:

Virtual environment: 

my_path\my_project\my_virtual_environment

Traceback (most recent call last)

File ...
    import sqlite3

File ...
    from sqlite3.dbapi2 import *

File ...
    from _sqlite3 import *

ImportError: DLL load failed: The specified module could not be found.

According to I read it is not necessary to import sqlite3.

I tried with virtualenv, as in the link, but I can't activate it.

If I create the virtual environment with Anaconda Navigator the code is executed correctly, but it creates the virtual environment directory in a subdirectory of Anaconda and not in the same directory of the project. This makes me wonder if when I create an executable with pyinstaller it will work.

Edited 16 March 2020

Working specifications:

Windows

  • Edition: Windows 10 Enterprise
  • Version: 1803
  • OS build: 17134.286

Python 3.7.6

CPU architecture

  • Intel Core i7-8700K CPU 3.70 GHz
  • RAM 32 GB
  • 64 bits
PedroBiel
  • 489
  • 1
  • 8
  • 21
  • You would probably get more feedback if you focused your question on a single topic. Is the involvement of _virtualenv_, _anaconda_, _pyinstaller_ really necessary to solve the issue with `import sqlite3`? – sinoroc Mar 09 '20 at 14:29
  • My first choice was `venv`. The rest are thoughts and things I've tried. – PedroBiel Mar 09 '20 at 17:56
  • Is a virtual environment (`venv` or something else) a necessary condition to trigger the error message or not? Does `path/to/python -c 'import sqlite3'` outside of any virtual environment trigger the error? – sinoroc Mar 09 '20 at 18:07
  • With regard to the first question, the error appears when the virtual environment is activated. When the code is executed in the base environment there is no error. Regarding the second question, no, it does not return an error. – PedroBiel Mar 10 '20 at 06:37
  • Maybe add some details that would allow people to try and reproduce the issue. Describe your environment as precisely as possible: operating system, python version, CPU architecture, etc. – sinoroc Mar 12 '20 at 09:41
  • Edited on 16 March 2020. – PedroBiel Mar 16 '20 at 11:36

1 Answers1

0

You will need to download the sqlite3 DLL and add it in the DLL's folder within your virtual environmnet. For using pyinstaller to package with the sqlite3, this might help you as I faced a similar issue.

The _sqlite3 import works through conda at runtime because it can access the _sqlite3.pyd file but for pyinstaller it needs the DLL that may be missing in your environment.

sid gupta
  • 11
  • 2