Skip to content

Commit b9bee52

Browse files
committed
Add PyInstaller spec file and Windows instructions
- This patch creates a spec file to build single-file binaries using PyInstaller and adds a markdown file with instructions for Windows users.
1 parent 8b8b347 commit b9bee52

4 files changed

Lines changed: 77 additions & 0 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ Tkinter.
55

66
![Screenshot](docs/2021-01-25-005820_448x480_scrot.png)
77

8+
## Windows
9+
10+
See [docs/windows.md](docs/windows.md).

docs/windows.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Windows
2+
3+
## Build
4+
5+
First, install chocolatey.
6+
7+
In powershell, run `choco install python --version 3.7.2`. **The version of python is important**. This project requires Python 3.6+ for typing and asyncio. Furthermore, pyinstaller only supports up to Python 3.7 as of January, 2021.
8+
9+
### Install virtualenv and create a new environment
10+
11+
In powershell, run `C:\Python37\python.exe -m pip install --user virtualenv`.
12+
13+
In powershell, run `C:\Python37\python.exe -m virtualenv env`.
14+
15+
Note: From here onward, we will use the virtualenv's python with `.\env\Scripts\python.exe`.
16+
17+
### Install Python packages
18+
19+
In powershell, run `.\env\Scripts\python.exe -m pip install -r requirements.txt`.
20+
21+
### Build a single executable with PyInstaller
22+
23+
In powershell, run `.\env\Scripts\python.exe -m pip install pyinstaller`.
24+
25+
In powershell, run `.\env\Scripts\pyinstaller.exe .\kasatk.spec`.
26+
27+
In powershell, your freshly built executable with `.\dist\kasatk.spec`.

kasatk.spec

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
3+
block_cipher = None
4+
5+
def kasa_dist_info_datas():
6+
"""find the kasa-python dist-info directory
7+
8+
pyinstaller doesn't seem to include the dist-info directory, which causes a runtime issue. This is a workaround.
9+
"""
10+
import os, sys
11+
for import_path in sys.path:
12+
if not os.path.isdir(import_path):
13+
continue
14+
for name in os.listdir(import_path):
15+
if "kasa" in name and name[-9:] == "dist-info":
16+
full_path = os.path.join(import_path, name)
17+
return (full_path, name)
18+
raise Exception("Could not find python-kasa dist info directory")
19+
20+
a = Analysis(['kasatk/__main__.py'],
21+
pathex=['.\\env\\Lib\\site-packages\\', '.'],
22+
binaries=[],
23+
datas=[kasa_dist_info_datas()],
24+
hiddenimports=[],
25+
hookspath=[],
26+
runtime_hooks=[],
27+
excludes=[],
28+
win_no_prefer_redirects=False,
29+
win_private_assemblies=False,
30+
cipher=block_cipher,
31+
noarchive=False)
32+
pyz = PYZ(a.pure, a.zipped_data,
33+
cipher=block_cipher)
34+
exe = EXE(pyz,
35+
a.scripts,
36+
a.binaries,
37+
a.zipfiles,
38+
a.datas,
39+
[],
40+
name='kasatk',
41+
debug=False,
42+
bootloader_ignore_signals=False,
43+
strip=False,
44+
upx=True,
45+
upx_exclude=[],
46+
runtime_tmpdir=None,
47+
console=True )

requirements.txt

98 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)