You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/tutorials/bundling_with_pyinstaller/index.rst
+47-20Lines changed: 47 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ Bundling a Game with PyInstaller
6
6
.. note::
7
7
8
8
You must have Arcade version 2.4.3 or greater and Pymunk 5.7.0 or greater
9
-
for the instructions below to work.*
9
+
for the instructions below to work.
10
10
11
11
You've written your game using Arcade_ and it is a masterpiece! Congrats! Now
12
12
you want to share it with others. That usually means helping people install
@@ -64,7 +64,7 @@ Handling Data Files
64
64
65
65
When creating a bundle, PyInstaller first examines your project and automatically identifies nearly everything your project needs (a Python interpreter,
66
66
installed modules, etc). But, it can't automatically determine what data files your game is loading from disk (images, sounds,
67
-
maps). So, you must explicitly tell PyInstaller about these files and where they should put them in the bundle.
67
+
maps). So, you must explicitly tell PyInstaller about these files and where it should put them in the bundle.
68
68
This is done with PyInstaller's ``--add-data`` flag:
69
69
70
70
.. code-block:: bash
@@ -76,14 +76,34 @@ PyInstaller should include in the bundle. The item after the semicolon is the "d
76
76
specifies where files should be placed in the bundle, relative to the bundle's root. In the example
77
77
above, the ``stripes.jpg`` image is copied to the root of the bundle ("``.``").
78
78
79
-
One thing to keep in mind. When you are packaging your game in a PyInstaller bundle,
80
-
you do not have control over what directory your executable will be run from. Therefore,
81
-
it is best to use relative path names in your Python code when loading data files. That
82
-
way your game will work no matter where people run the bundled executable from.
79
+
After instructing PyInstaller to include data files in a bundle, you must make sure your code loads
80
+
the data files from the correct directory. When you share your game's bundle, you have no control over what directory
81
+
the user will run your bundle from. This is complicated by the fact that a one-file PyInstaller
82
+
bundle is uncompressed at runtime to a random temporary directory and then executed from there. This document describes
83
+
one simple approach that allows your code to execute and load files when running in a PyInstaller bundle AND also be
84
+
able to run when not bundled.
83
85
84
-
Below are some examples that show a few common patterns of how data files can be bundled.
85
-
The examples first show a code snippet that demonstrates how data is loaded, followed by the PyInstaller
86
-
command to bundle it up.
86
+
You need to do two things. First, the snippet below must be placed at the beginning of your script:
0 commit comments