Pyinstaller Pyqt 6 and a SQLITE database
-
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!
I 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.
-
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.@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? -
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.
@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?@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?
-
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?
@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.
-
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.