4

I have looked at other threads about this topic, and so far I haven't had any luck.

I am trying to use pyinstaller to create an .exe that validates data. I can successfully create an executable, and it will run, but the sqlite3 part of the code isn't working.

I get the following error:

File "cold_call.py", line 6, in File "/tmp/_MEIOlQDSM/mainFrame.py", line 18, in import userDefine File "/tmp/_MEIOlQDSM/userDefine.py", line 20, in import work_db_common File "/tmp/_MEIOlQDSM/work_db_common.py", line 4, in import sqlite3 File "/tmp/_MEIOlQDSM/sqlite3/init.py", line 23, in from sqlite3.dbapi2 import * File "/tmp/_MEIOlQDSM/sqlite3/dbapi2.py", line 27, in from _sqlite3 import * ImportError: No module named '_sqlite3'

but when I run python3 my_file.py it works fine with sqlite3.

I am using python3.4 on opensuse 42.3.

sqlite3 packages installed from zypper

i+ | libsqlite3-0 | Shared libraries for the Embeddable SQL Database Engine | package

i+ | sqlite3 | Embeddable SQL Database Engine | package

i+ | sqlite3-devel | Embeddable SQL Database Engine | package

I have tried to reinstall python3, but it still doesn't work.

then, in *.spec file I wrote the following script:

def get_sqlite3_path():                                                                 
    import sqlite3                                                                  
    sqlite3_path = sqlite3.__path__[0]                                              
    print('sqlite3_path = {}'.format(sqlite3_path))                                 
    return sqlite3_path 
...
dict_tree = Tree(get_sqlite3_path(), prefix='sqlite3', excludes=["*.pyc"])              
a.datas += dict_tree                                                                    
a.binaries = filter(lambda x: 'sqlite3' not in x[0], a.binaries) 

no success!

Any idea how to fix this problem?

P.S This code

print('sqlite3_path = {}'.format(sqlite3_path))

returns

sqlite3_path = /usr/lib64/python3.4/sqlite3

Marseille
  • 41
  • 1
  • 5

1 Answers1

5

This answer resolved the issue.

Add --hidden-import=sqlite3 while building exe.

pyinstaller your_script.py --onefile --hidden-import=sqlite3

Ahsan
  • 11,516
  • 12
  • 52
  • 79