Sqlite inoperative in Python executable program created by cx_Freeze

Asked

Viewed 138 times

0

I made a simple application in Python 3.6 and Sqlite3.

When I run the main program by cx_Freeze and install it on the machine I developed the application on (where Python and Sqlite are installed), the application works well, including deleting, consulting and changing the data in the databases.

The problem is when I install this application on another computer that does not have Python or Sqlite installed. When there is an interaction with the databases, no error returns and simply the program gives no answer, as if not accessing the databases.

What do I still need to put in the setup.py file so the application can effectively access Sqlite databases? I have to put some more command in the programs that access the bases?
To assist, I refer below the setup.py program and a program that accesses the Sqlite.

Program setup.py:

#setup.py
import os
import sys
os.environ['TCL_LIBRARY'] = "C:\\Users\\Paulo\\AppData\\Local\\Programs\\Python\\Python36\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Users\\Paulo\\AppData\\Local\\Programs\\Python\\Python36\\tcl\\tk8.6"
from cx_Freeze import setup, Executable
setup(
name = "Sistema RMI",
version = "1.0.2",
options = {"build_exe": {
    'packages': ["os","sys","ctypes","time","sqlite3","datetime"],
    'include_files':[r"C:\Users\Paulo\AppData\Local\Programs\Python\Python36\DLLs\tcl86t.dll", 
                     r"C:\Users\Paulo\AppData\Local\Programs\Python\Python36\DLLs\tk86t.dll", 
                     r"C:\Users\Paulo\AppData\Local\Programs\Python\Python36\DLLs\sqlite3.dll"],
    'include_msvcr': True,
}},
executables = [Executable("PgmPrin.py",base="win32GUI")]
)

Program that accesses database:

import sqlite3

class BancoInpcDB():

    def __init__(self):
        self.conexao = sqlite3.connect('bancoInpcDB.db')
        self.createTable()

    def createTable(self):
        c = self.conexao.cursor()

        c.execute("""create table if not exists inpc (
                    anomes integer primary key ,
                    percentual numeric(2,4) not null,
                    validacao char(1) not null)""")

        self.conexao.commit()
        c.close()

1 answer

0

I figured out what was going on. I tried to make an Insert in one of the Sqlite files of my system, through Firefox Sqllite Manager, and I received the following message: "NS_ERROR_FILE_READ_ONLY", ie, was missing authorization as administrator of the directory to be able to access the application. So I ran my application as an administrator and the system started working properly. Thus, there were no problems with Sqlite and what was missing was a little more experience in developing with Python to inform in the error message the real problem that was occurring with the access to the database.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.