Pyinstaller Pyqt 6 and a SQLITE database
-
wrote on 8 Sept 2022, 11:06 last edited by
Hello,
I made an exe file out of my Python /Qt database application. I copied the database into the dist directory in which the exe file is located and started the program. There was no error message, but my database was not displayed in QTableView().Question:
What do I have to do so that my database is displayed when the exe file is started? -
Hi,
What is the path that are you using in your application ?
On a side note, putting your database in the same folder as your application is usually a bad idea as the application might be installed in a shared folder that will likely be read-only. You should rather use QStandardPaths and retrieve an appropriate folder to store your database.
-
Hello,
I made an exe file out of my Python /Qt database application. I copied the database into the dist directory in which the exe file is located and started the program. There was no error message, but my database was not displayed in QTableView().Question:
What do I have to do so that my database is displayed when the exe file is started?wrote on 8 Sept 2022, 11:28 last edited by@PythonQTMarlem said in Pyinstaller Pyqt 6 and a SQLITE database:
There was no error message
In addition to @SGaist. Assuming it failed to find the database file to open, it is your responsibility to check that result and issue an informative error message. Then you/your user would have known what the problem is....
-
wrote on 8 Sept 2022, 15:49 last edited by
Thank you for the answers. You're right:
D:\Temp_MEI82162\adressen_verwaltung.db . The database is really not there. But why doesn't this work:filename = os.path.join(os.path.dirname(__file__), "address_management.db")
I do not get it!
-
Thank you for the answers. You're right:
D:\Temp_MEI82162\adressen_verwaltung.db . The database is really not there. But why doesn't this work:filename = os.path.join(os.path.dirname(__file__), "address_management.db")
I do not get it!
wrote on 8 Sept 2022, 16:13 last edited by JonB 9 Aug 2022, 16:16I copied the database into the dist directory in which the exe file is located
And what directory is that? What directory is the
__file__
this code is in? Have you printed it out? Use Python code to test whether that path even exists.BTW, if you're not careful: left to its own devices, (I believe) SQLite creates an empty database at the specified path if it does not already exist, you might end up creating and opening an empty database.
-
wrote on 8 Sept 2022, 16:28 last edited by
when i start my programm in pycharm this:
print(os.path.abspath(__file__))
shows the directory in which my Python file is located.
that's right!
when I start the exe-file, it shows D:\Temp_MEI82162.
That's wrong. -
when i start my programm in pycharm this:
print(os.path.abspath(__file__))
shows the directory in which my Python file is located.
that's right!
when I start the exe-file, it shows D:\Temp_MEI82162.
That's wrong.wrote on 8 Sept 2022, 16:32 last edited by JonB 9 Aug 2022, 16:35@PythonQTMarlem
I don't know what the "exe" file is, given that you are talking about Python. It looks like something extracts files into theD:\Temp_...
directory and then runs something there. If you take the time to look in that directory while this is running you will presumably see files there. Please do not say it is "wrong", try to understand what is going on. I know nothing about what a "Pyinstaller Pyqt 6" is. Is whatever this "exe" is a self-extracting zip/.exe
file? -
wrote on 8 Sept 2022, 17:05 last edited by
in order. I'm trying to understand. An exe file (for example main.exe ) is an executable file in the Windows operating system.
-
in order. I'm trying to understand. An exe file (for example main.exe ) is an executable file in the Windows operating system.
wrote on 8 Sept 2022, 17:13 last edited by JonB 9 Aug 2022, 17:14@PythonQTMarlem
LOL, I know what an.exe
file is! :) What I mean is, (unlike C++) a Python program is not/does not produce a.exe
file. So I don't know how you have one, or what it does, it is something to do with "Pyinstaller Pyqt 6". Or, what does your "I made an exe file out of my Python /Qt database application" mean, am I supposed to know, how did you do that?My guess is that you have some kind of self-extracting zip file as your
.exe
. My guess is that it contains your.py
source files. My guess is that running it extracts these to someD:\Temp...
directory and then runs the Python 3 interpreter on them (and it probably deletes that directory at end of Python program, so you may only see them while the script is still running). All of which would lead toos.path.dirname(__file__)
being there, not where you expect, not where your database file lives? -
@PythonQTMarlem
LOL, I know what an.exe
file is! :) What I mean is, (unlike C++) a Python program is not/does not produce a.exe
file. So I don't know how you have one, or what it does, it is something to do with "Pyinstaller Pyqt 6". Or, what does your "I made an exe file out of my Python /Qt database application" mean, am I supposed to know, how did you do that?My guess is that you have some kind of self-extracting zip file as your
.exe
. My guess is that it contains your.py
source files. My guess is that running it extracts these to someD:\Temp...
directory and then runs the Python 3 interpreter on them (and it probably deletes that directory at end of Python program, so you may only see them while the script is still running). All of which would lead toos.path.dirname(__file__)
being there, not where you expect, not where your database file lives?wrote on 8 Sept 2022, 17:56 last edited by@JonB The _MEI111282 directory is temporarily created when my Python application is running. In this directory there is a directory "PyQt6" and my database file adressen_verwaltung.db which has 0kb. When I exit my python file, that directory gets deleted again!
The question is: Why is this directory created?
-
wrote on 8 Sept 2022, 18:06 last edited by
This works: filename = "adressen_verwaltung.db" .
Just skip all the effort to create cross-platform paths. Now I have to test whether it also works in the operating systems Ubuntu and MacOS. -
@JonB The _MEI111282 directory is temporarily created when my Python application is running. In this directory there is a directory "PyQt6" and my database file adressen_verwaltung.db which has 0kb. When I exit my python file, that directory gets deleted again!
The question is: Why is this directory created?
wrote on 8 Sept 2022, 18:08 last edited by JonB 9 Aug 2022, 18:11@PythonQTMarlem said in Pyinstaller Pyqt 6 and a SQLITE database:
The question is: Why is this directory created?
That is exactly what I explained, at least to the best of my ability/knowledge.
-
wrote on 8 Sept 2022, 18:14 last edited by
Yes, but I didn't read anything in the Pyinstaller documentation that the exe file is some kind of zip file.
-
This works: filename = "adressen_verwaltung.db" .
Just skip all the effort to create cross-platform paths. Now I have to test whether it also works in the operating systems Ubuntu and MacOS.@PythonQTMarlem said in Pyinstaller Pyqt 6 and a SQLITE database:
This works: filename = "adressen_verwaltung.db" .
As I already wrote earlier, creating a read/write file in the same folder as the application is a bad idea. It will work for installs that are made in a user local folder (for example in their home folder) but that will break as soon as it is done system wide. You are also ignoring the case were your application is used by several people on the same machine that will likely not want to share a single database with each other.
On a side note, unless you are providing a command line application, macOS does not like for their App bundle to be modified withing themselves.
@PythonQTMarlem said in Pyinstaller Pyqt 6 and a SQLITE database:
This works: filename = "adressen_verwaltung.db" .
Just skip all the effort to create cross-platform paths. Now I have to test whether it also works in the operating systems Ubuntu and MacOS.That's a bit of a strange take since you are using a cross-platform toolkit through a cross-platform language while said toolkit offers a clean and simple way to handle that kind of path.
1/14