Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Pyinstaller Pyqt 6 and a SQLITE database
Forum Updated to NodeBB v4.3 + New Features

Pyinstaller Pyqt 6 and a SQLITE database

Scheduled Pinned Locked Moved Unsolved Qt for Python
14 Posts 3 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PythonQTMarlem
    wrote on 8 Sept 2022, 11:06 last edited by
    #1

    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?

    J 1 Reply Last reply 8 Sept 2022, 11:28
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 8 Sept 2022, 11:11 last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • P PythonQTMarlem
        8 Sept 2022, 11:06

        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?

        J Online
        J Online
        JonB
        wrote on 8 Sept 2022, 11:28 last edited by
        #3

        @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....

        1 Reply Last reply
        0
        • P Offline
          P Offline
          PythonQTMarlem
          wrote on 8 Sept 2022, 15:49 last edited by
          #4

          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!

          J 1 Reply Last reply 8 Sept 2022, 16:13
          0
          • P PythonQTMarlem
            8 Sept 2022, 15:49

            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!

            J Online
            J Online
            JonB
            wrote on 8 Sept 2022, 16:13 last edited by JonB 9 Aug 2022, 16:16
            #5

            @PythonQTMarlem

            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.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              PythonQTMarlem
              wrote on 8 Sept 2022, 16:28 last edited by
              #6

              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.

              J 1 Reply Last reply 8 Sept 2022, 16:32
              0
              • P PythonQTMarlem
                8 Sept 2022, 16:28

                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.

                J Online
                J Online
                JonB
                wrote on 8 Sept 2022, 16:32 last edited by JonB 9 Aug 2022, 16:35
                #7

                @PythonQTMarlem
                I don't know what the "exe" file is, given that you are talking about Python. It looks like something extracts files into the D:\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?

                1 Reply Last reply
                1
                • P Offline
                  P Offline
                  PythonQTMarlem
                  wrote on 8 Sept 2022, 17:05 last edited by
                  #8

                  in order. I'm trying to understand. An exe file (for example main.exe ) is an executable file in the Windows operating system.

                  J 1 Reply Last reply 8 Sept 2022, 17:13
                  0
                  • P PythonQTMarlem
                    8 Sept 2022, 17:05

                    in order. I'm trying to understand. An exe file (for example main.exe ) is an executable file in the Windows operating system.

                    J Online
                    J Online
                    JonB
                    wrote on 8 Sept 2022, 17:13 last edited by JonB 9 Aug 2022, 17:14
                    #9

                    @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 some D:\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 to os.path.dirname(__file__) being there, not where you expect, not where your database file lives?

                    P 1 Reply Last reply 8 Sept 2022, 17:56
                    1
                    • J JonB
                      8 Sept 2022, 17:13

                      @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 some D:\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 to os.path.dirname(__file__) being there, not where you expect, not where your database file lives?

                      P Offline
                      P Offline
                      PythonQTMarlem
                      wrote on 8 Sept 2022, 17:56 last edited by
                      #10

                      @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?

                      J 1 Reply Last reply 8 Sept 2022, 18:08
                      0
                      • P Offline
                        P Offline
                        PythonQTMarlem
                        wrote on 8 Sept 2022, 18:06 last edited by
                        #11

                        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.

                        S 1 Reply Last reply 9 Sept 2022, 06:34
                        0
                        • P PythonQTMarlem
                          8 Sept 2022, 17:56

                          @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?

                          J Online
                          J Online
                          JonB
                          wrote on 8 Sept 2022, 18:08 last edited by JonB 9 Aug 2022, 18:11
                          #12

                          @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.

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            PythonQTMarlem
                            wrote on 8 Sept 2022, 18:14 last edited by
                            #13

                            Yes, but I didn't read anything in the Pyinstaller documentation that the exe file is some kind of zip file.

                            1 Reply Last reply
                            0
                            • P PythonQTMarlem
                              8 Sept 2022, 18:06

                              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.

                              S Offline
                              S Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 9 Sept 2022, 06:34 last edited by
                              #14

                              @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.

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              1

                              1/14

                              8 Sept 2022, 11:06

                              • Login

                              • Login or register to search.
                              1 out of 14
                              • First post
                                1/14
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved