Skip to content

Commit 0361d8d

Browse files
committed
Update PyInstaller example.
1 parent 597f2b8 commit 0361d8d

File tree

6 files changed

+70
-17
lines changed

6 files changed

+70
-17
lines changed
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
PyInstaller Example
22
===================
33

4-
First, install the packages: ``tcod`` and ``PyInstaller``.
4+
It's recommended to use a virtual environment to package Python executables.
5+
Use the following guide on how to set one up:
6+
https://docs.python.org/3/tutorial/venv.html
57

6-
On Windows you must also install the ``pywin32`` package
7-
(named ``pypiwin32`` if you're using pip install.)
8+
Once the virtual environment is active you should install ``tcod``, ``PyInstaller``, and ``pypiwin32`` if on Windows from the ``requirements.txt`` file:
89

9-
Then run the PyInstaller script with this command::
10+
pip install -r requirements.txt
1011

11-
PyInstaller hello_world.py --add-data "terminal8x8_gs_ro.png;."
12+
Then run PyInstaller on the included Spec file::
13+
14+
PyInstaller main.spec
1215

1316
The finished build will be placed in the ``dist/`` directory.
1417

15-
You can also build to one executable file using the following command::
18+
You can also build to one file using the following command::
19+
20+
PyInstaller main.spec --onefile
21+
22+
Single file distributions have performance downsides so it is preferred to distribute a larger program this way.
1623

17-
PyInstaller hello_world.py --add-data "terminal8x8_gs_ro.png;." --onefile
24+
For `tcod` it is recommended to set the ``PYTHONOPTIMIZE=1`` environment variable before running PyInstaller. This disables warnings for `tcod`'s deprecated functions and will improve the performance of those functions if you were using them.
1825

19-
The PyInstaller manual can be found at: https://pythonhosted.org/PyInstaller/
26+
The PyInstaller documentation can be found at: https://pythonhosted.org/PyInstaller/

examples/distribution/PyInstaller/terminal8x8_gs_ro.png renamed to examples/distribution/PyInstaller/data/terminal8x8_gs_ro.png

File renamed without changes.
19.7 KB
Binary file not shown.

examples/distribution/PyInstaller/hello_world.py renamed to examples/distribution/PyInstaller/main.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,22 @@
1313
# The base directory, this is sys._MEIPASS when in one-file mode.
1414
BASE_DIR = getattr(sys, "_MEIPASS", ".")
1515

16-
FONT_PATH = os.path.join(BASE_DIR, "terminal8x8_gs_ro.png")
16+
FONT_PATH = os.path.join(BASE_DIR, "data/terminal8x8_gs_ro.png")
1717

1818

1919
def main():
20-
tcod.console_set_custom_font(FONT_PATH, tcod.FONT_LAYOUT_CP437)
21-
with tcod.console_init_root(
22-
WIDTH, HEIGHT, renderer=tcod.RENDERER_SDL2, vsync=True
23-
) as console:
20+
tileset = tcod.tileset.load_tilesheet(
21+
FONT_PATH, 16, 16, tcod.tileset.CHARMAP_CP437
22+
)
23+
with tcod.context.new(
24+
columns=WIDTH, rows=HEIGHT, tileset=tileset
25+
) as context:
2426
while True:
25-
console.clear()
27+
console = tcod.console.Console(WIDTH, HEIGHT)
2628
console.print(0, 0, "Hello World")
27-
tcod.console_flush()
28-
29+
context.present(console)
2930
for event in tcod.event.wait():
30-
if event.type == "QUIT":
31+
if isinstance(event, tcod.event.Quit):
3132
raise SystemExit()
3233

3334

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
3+
block_cipher = None
4+
5+
6+
a = Analysis(
7+
["main.py"],
8+
binaries=[],
9+
datas=[("data", "data")], # Include all files in the 'data' directory.
10+
hiddenimports=[],
11+
hookspath=[],
12+
runtime_hooks=[],
13+
excludes=[],
14+
win_no_prefer_redirects=False,
15+
win_private_assemblies=False,
16+
cipher=block_cipher,
17+
noarchive=False,
18+
)
19+
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
20+
exe = EXE(
21+
pyz,
22+
a.scripts,
23+
[],
24+
exclude_binaries=True,
25+
name="start", # Name of the executable.
26+
debug=False,
27+
bootloader_ignore_signals=False,
28+
strip=False,
29+
upx=True,
30+
console=True, # Set to False to disable the Windows terminal.
31+
icon="icon.ico", # Windows icon file.
32+
)
33+
coll = COLLECT(
34+
exe,
35+
a.binaries,
36+
a.zipfiles,
37+
a.datas,
38+
strip=False,
39+
upx=True,
40+
upx_exclude=[],
41+
name="hello_world", # Name of the distribution directory.
42+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
tcod==12.2.0
2+
pyinstaller==4.2
3+
pypiwin32; sys_platform=="win32"

0 commit comments

Comments
 (0)