I've got a PyQt4 application which makes use of sqlite3. I have two seperate files currently: a .py file and a .db file. Originally I took the .py file and tried to create an executable just using that thinking maybe it would link somehow but when I run the .exe it breaks when it gets to database related code. How do I get pyinstaller to include the database as well?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
This post helped me. Basically, you can run the pyinstaller command with arguments as follows (assuming your script is
script.py
and your database isdatabase.db
):This will first create a
.spec
file that listsdatabase.db
as a file to be included in your build. The created.spec
file will then be used to run the build.As explained here, the -w option prevents a console from being displayed when you run the
.exe
file that will be created.---- Alternatively ----
According to the docs, you can first create just the
.spec
file and then modify it to list the data files that should be included. The.spec
file forscript.py
is created using:Then, within the
.spec
file created, you can modify thedatas
field:This assumes that
database.db
is in the root folder. If not, you will need to include the path. The'.'
specifies where you want the database file to be located in the build (in this case,'.'
is the root folder). To include more files, you can add more tuples('<file>', '<path>')
to thedatas
list.You need to use a specfile. Have a look at the documentation.
pyinstaller creates those file automatically. You just need to edit it. Have a look at the example from the docs. To add a README file you just need to add a tuple (source, destination) to 'datas':