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
Instead of embedding the .zip, onefile_python.exe will download the
python-embedded zip on each run. Download URL can be set through flags
or the .exe name.
Copy file name to clipboardExpand all lines: README.md
+46-6Lines changed: 46 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,23 +2,63 @@
2
2
3
3
Run python from a single exe (without needing to extract anything to disk).
4
4
5
-
This project uses reflective dll loading and nim's `staticRead` to load the python runtime from the executable itself.
5
+
This project uses reflective dll loading and either nim's `staticRead` to load the python runtime from the executable itself, or optionally downloads the embedded zip on launch ("staged" mode).
6
6
Custom (python) import hooks are installed to support loading modules (both native python (.pyc) and extension modules (.pyd)) from the embedded standard library.
7
7
8
-
## HOWTO
8
+
## Building
9
+
10
+
Or just download from from the [releases page](https://github.com/synap5e/onefile_python/releases).
9
11
10
12
0. Set up nim
13
+
14
+
### Zip embedded in file
15
+
11
16
1. Download `python-3.10.1-embed-amd64.zip` to the project directory
12
17
2.`nimble build`
13
18
3. Run `onefile_python.exe`
14
19
15
-
## TODO
20
+
### Download zip on launch ("staged")
21
+
22
+
Potentially useful if you want a smaller exe.
23
+
24
+
1.`nimble build -d:staged`
25
+
2. Run `onefile_python.exe`
26
+
27
+
28
+
## Usage
29
+
30
+
```
31
+
onefile_python
16
32
17
-
Currently the exe just drops to an interactive loop. Modification to run a script or embed a file/module should be trivial.
33
+
Usage:
34
+
onefile_python [options] [file] [arg ...]
18
35
19
-
-[ ] Build option for embedding a python file/module and running that on launch
36
+
Arguments:
37
+
[file] Program; read from script file/URL ('-' or empty for interactive) (default: )
38
+
[arg ...] Arguments passed to program in sys.argv[1:]
39
+
40
+
Options:
41
+
-h, --help
42
+
-V, --version
43
+
-c, --command=COMMAND Program; passed in as string
44
+
```
45
+
`file` can be a http or https URL.
46
+
47
+
For staged version:
48
+
```
49
+
-d, --download=DOWNLOAD Download `python-3.10.1-embed-amd64.zip` from this url (default: https://www.python.org/ftp/python/3.10.1)
50
+
51
+
```
52
+
53
+
Alternatively specify the download URL in the app filename e.g. rename `onefile_python.exe` to `blabla(10.0.0.1)foobar.exe` to download python from `https://10.0.0.1/python-3.10.1-embed-amd64.zip`. `blabla` and `foobar` can be any string.
54
+
55
+
56
+
## TODO
57
+
58
+
-[ ] Build option for embedding a python file/module and running that on launch (instead of accepting file/interactive loop)
20
59
-[ ] Support other versions of python than `3.10.1` (autodetect?)
@@ -39,7 +79,7 @@ Being simpler, this project should be easier to hack on or learn from.
39
79
40
80
There's not much to it...
41
81
42
-
0. Use nim's [staticRead](https://nim-lang.org/docs/system.html#staticRead%2Cstring) to include `python-*-embedded.zip` and `bootstrap.py` inside compiled exe itself.
82
+
0. Use nim's [staticRead](https://nim-lang.org/docs/system.html#staticRead%2Cstring) to include `python-*-embedded.zip` and `bootstrap.py` inside compiled exe itself OR download the zip from a URL.
43
83
1. Use [zippy](https://github.com/guzba/zippy) to access the contents of the archive at runtime.
44
84
2. Use [memlib](https://github.com/khchen/memlib) to perform reflective dll loading of the embedded `python*.dll`. Reflective dll loading allows for loading the dll from memory rather than from disk. Hook `LdrLoadDll` and `K32EnumProcessModules` so other code using the dll can find it. n.b. currently using a fork until https://github.com/khchen/memlib/pull/3 is merged.
45
85
3. Call various functions in the (reflectively) loaded dll to partially initialize python. Configure python to not try to load anything from disk (not absolutely required, but prevents conflicts and means the exe doesn't run any code in the current directory)
Copy file name to clipboardExpand all lines: onefile_python.nim
+23-1Lines changed: 23 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -19,13 +19,22 @@ const DEBUG = false # Print debug messages (in nim code, and in python loaders)
19
19
constEMBED_DLL=true# Use the .dll embedded in the zip archive. If false, will require python310.dll to be in the PATH. If true, debugging may be harder as the dll is reflectively loaded
option("-c", "--command", help="Program; passed in as string")
27
30
arg("file", default=some(""), help="Program; read from script file/URL ('-' or empty for interactive)")
28
31
arg("arg", nargs=(-1), help="Arguments passed to program in sys.argv[1:]")
32
+
whendefined(staged):
33
+
option("-d", "--download", help=fmt"Download `{PYTHON_EMBEDDED_FILE}` from this url", default=some(PYTHON_EMBEDDED_URL))
34
+
whendefined(staged):
35
+
const extra_help = fmt"Alternatively specify the download URL in the app filename e.g. `blabla(10.0.0.1)foobar.exe` means download from `https://10.0.0.1/{PYTHON_EMBEDDED_FILE}`."
0 commit comments