# Installer creation based on distributions

**URL:** <https://discuss.python.org/t/installer-creation-based-on-distributions/34576>\
**Category:** Packaging\
**Tags:** help\
**Created:** [September 24, 2023, 9:49pm UTC](https://discuss.python.org/t/installer-creation-based-on-distributions/34576 "2023-09-24T21:49:28Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![pf\_moore](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/pf_moore/32/35_2.png) [@pf\_moore](https://discuss.python.org/u/pf_moore)\
**Post date:** [October 16, 2024, 3:14pm UTC](https://discuss.python.org/t/installer-creation-based-on-distributions/34576/22 "2024-10-16T15:14:32Z")

</div>

> [@oscarbenjamin](#):
>
> It is a long time since I used pyinstaller (or anything similar) so maybe it already provides this now…

My understanding is that pyInstaller doesn’t work at the package level at all, but at the individual import module level. So it scans the source code looking to see what specific components of (say) scipy are used, and only includes them in the application. That gives significant space savings (especially with a large library like scipy) but it’s fragile in the face of dynamic imports and similar runtime tricks for loading modules.

I believe there are heuristics that handle conditional imports in well-known libraries, but that doesn’t help with actual application code. As I said above, my (very limited) experience is that it’s a good approach for pyInstaller’s target audience, but it doesn’t fit well for some use cases. I’ve not tried the approach mentioned above of customising things via the `Analysis` API, so it may be that offers a way of working round this.

The key thing is that as I understand it, pyInstaller scans the application _environment_ and extracts the necessary files from that. It doesn’t work with wheels, or any other packaging distribution files, at all.

The above may be inaccurate - whenever I’ve tried to read the pyInstaller documentation, which hasn’t been for some time, I’ve found it hard to follow precisely because its perspective is based around freezing an _environment_, and not around packages and dependencies, etc, like I’m used to. So the terminology and context is very different to what I am used to.

---

<div class="post-metadata">

**Author:** ![bwoodsend](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/bwoodsend/32/4027_2.png) [@bwoodsend](https://discuss.python.org/u/bwoodsend)\
**Post date:** [October 16, 2024, 4:42pm UTC](https://discuss.python.org/t/installer-creation-based-on-distributions/34576/23 "2024-10-16T16:42:55Z")

</div>

> [@oscarbenjamin](#):
>
> Do any of the options above provide this sort of bundling where you just give it the output of `pip freeze` and a directory of wheels?

Last I checked, PyOxidiser just uses wheels. But it also rewrites all your (probably not zip safe) packages and extension modules into one big file which brings in a new world of ways to go wrong so I wouldn’t consider the problem of a packaging tool based on wheels or metadata to be solved.

---

<div class="post-metadata">

**Author:** ![oscarbenjamin](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/oscarbenjamin/32/1209_2.png) [@oscarbenjamin](https://discuss.python.org/u/oscarbenjamin)\
**Post date:** [October 16, 2024, 4:53pm UTC](https://discuss.python.org/t/installer-creation-based-on-distributions/34576/24 "2024-10-16T16:53:00Z")

</div>

> [@pf\_moore](#):
>
> My understanding is that pyInstaller doesn’t work at the package level at all, but at the individual import module level.

You can apply the same sort of idea there though and just say that you give a complete list of which import packages from site-packages should be included. Then pyinstaller or other tools could be used to help create that list and you could maybe make some manual changes.

Alternatively if you have the output of `pip freeze` and the directory of wheels then you can generate a venv with the installed packages. Then you just need a way to tell pyinstaller to skip import scanning and include the whole of site-packages.

---

<div class="post-metadata">

**Author:** ![anon62990384](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@anon62990384](https://discuss.python.org/u/anon62990384)\
**Post date:** [October 16, 2024, 5:02pm UTC](https://discuss.python.org/t/installer-creation-based-on-distributions/34576/25 "2024-10-16T17:02:53Z")

</div>

Late to this. I have not traditionally lurked in the packaging channels.

> [@jeanas](#):
>
> My question is: do you know a tool that will _not_ try to be smart and will simply (well, “simply”) take a package, resolve dependencies like `pip`, and bundle the contents of all wheels (with the Python interpreter plus an installer icon and such)?

Yes - minus the installer icon, since this produces a “scie” which is self-installing, you can use [Pex](https://pypi.org/project/pex/): `pex [the package] -c [console script entry point] --scie eager -o my-self-installing-native-executable`. If you don’t have a console script entry point you can use `-m module` or `-e package.module:function`.

For example:

```python
:; pex f2-commander -c f2 --scie eager -o f2

:; file f2
f2: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), static-pie linked, BuildID[sha1]=f1f01ca2ad165fed27f8304d4b2fad02dcacdffe, stripped

:; zipinfo -1 f2 | grep METADATA
warning [f2]: 31530344 extra bytes at beginning or within zipfile
  (attempting to process anyway)
.deps/Send2Trash-1.8.3-py3-none-any.whl/Send2Trash-1.8.3.dist-info/METADATA
.deps/f2_commander-0.1.0-py3-none-any.whl/f2_commander-0.1.0.dist-info/METADATA
.deps/humanize-4.11.0-py3-none-any.whl/humanize-4.11.0.dist-info/METADATA
.deps/linkify_it_py-2.0.3-py3-none-any.whl/linkify_it_py-2.0.3.dist-info/METADATA
.deps/markdown_it_py-3.0.0-py3-none-any.whl/markdown_it_py-3.0.0.dist-info/METADATA
.deps/mdit_py_plugins-0.4.2-py3-none-any.whl/mdit_py_plugins-0.4.2.dist-info/METADATA
.deps/mdurl-0.1.2-py3-none-any.whl/mdurl-0.1.2.dist-info/METADATA
.deps/platformdirs-4.3.6-py3-none-any.whl/platformdirs-4.3.6.dist-info/METADATA
.deps/pygments-2.18.0-py3-none-any.whl/pygments-2.18.0.dist-info/METADATA
.deps/python_dotenv-1.0.1-py3-none-any.whl/python_dotenv-1.0.1.dist-info/METADATA
.deps/rich-13.9.2-py3-none-any.whl/rich-13.9.2.dist-info/METADATA
.deps/textual-0.83.0-py3-none-any.whl/textual-0.83.0.dist-info/METADATA
.deps/typing_extensions-4.12.2-py3-none-any.whl/typing_extensions-4.12.2.dist-info/METADATA
.deps/uc_micro_py-1.0.3-py3-none-any.whl/uc_micro_py-1.0.3.dist-info/METADATA

```

Running `./f2` nets you:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/python1/original/3X/5/2/52930ddeba2f489c72fc3d96edc4ce66df8b7d30.png)

Although all the machinery existed for this since November 2022 using the scie jump directly and using the higher level `science` tool since May 2023 (See [Science · GitHub](https://github.com/a-scie)), Pex only incorporated that machinery for convenience in 2.11.0 in July. Maybe this helps.

---

<div class="post-metadata">

**Author:** ![pf\_moore](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/pf_moore/32/35_2.png) [@pf\_moore](https://discuss.python.org/u/pf_moore)\
**Post date:** [October 16, 2024, 5:36pm UTC](https://discuss.python.org/t/installer-creation-based-on-distributions/34576/26 "2024-10-16T17:36:14Z")

</div>

> [@anon62990384](#):
>
> Yes - minus the installer icon, since this produces a “scie” which is self-installing, you can use [Pex](https://pypi.org/project/pex/)

Does pex support Windows these days? Last time I checked, it didn’t and they had no plans to do so.

---

<div class="post-metadata">

**Author:** ![anon62990384](https://avatars.discourse-cdn.com/v4/letter/a/b4bc9f/32.png) [@anon62990384](https://discuss.python.org/u/anon62990384)\
**Post date:** [October 16, 2024, 5:44pm UTC](https://discuss.python.org/t/installer-creation-based-on-distributions/34576/27 "2024-10-16T17:44:06Z")

</div>

> [@pf\_moore](#):
>
> Does pex support Windows these days? Last time I checked, it didn’t and they had no plans to do so.

It does not. They is me (or has been for the last 5 years or so) and I do plan to do so. I have in fact been torturing myself using Windows for the last 2 years to force this issue (I prefer Linux). My bar has been high though, full green CI to land the 1st support, and that has been slow!

That said, the `science` executable _does_ support Windows and is written in Python and uses shiv for the moment since it does support Windows. That dogfood is here for example: [lift/lift.toml at main · a-scie/lift · GitHub](https://github.com/a-scie/lift/blob/main/lift.toml)

A few more steps than just `pex --scie eager`, but not too hard either.

---

<div class="post-metadata">

**Author:** ![ofek](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/ofek/32/1033_2.png) [@ofek](https://discuss.python.org/u/ofek)\
**Post date:** [October 17, 2024, 8:54pm UTC](https://discuss.python.org/t/installer-creation-based-on-distributions/34576/28 "2024-10-17T20:54:17Z")

</div>

> [@oscarbenjamin](#):
>
> I would actually rather go one step further and say that I would want pyinstaller (or others) to take something more like the output of pip freeze and to take all wheels from a local directory. […] I could then use any other tool to obtain the wheels and to decide exactly which packages and versions I want.

[PyApp](https://github.com/ofek/pyapp) will support this in future. Currently you can (among other options) supply a premade distribution or a requirements.txt-style file for runtime installation. The binaries for Hatch now use a premade distribution so installation is just a single download and unpack operation.

> [@pf\_moore](#):
>
> Does pex support Windows these days?

PyApp supports Windows, I forget if you’ve tried that yet.

---

<div class="post-metadata">

**Author:** ![pf\_moore](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/pf_moore/32/35_2.png) [@pf\_moore](https://discuss.python.org/u/pf_moore)\
**Post date:** [October 17, 2024, 9:21pm UTC](https://discuss.python.org/t/installer-creation-based-on-distributions/34576/29 "2024-10-17T21:21:01Z")

</div>

> [@ofek](#):
>
> PyApp supports Windows, I forget if you’ve tried that yet.

I have. I consider it to be a fundamentally different approach (that isn’t what I want from an “tool that builds a standalone application from Python code”). But we’ve had this debate before and it’s likely fruitless to repeat it.

---

<div class="post-metadata">

**Author:** ![takluyver](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/takluyver/32/513_2.png) [@takluyver](https://discuss.python.org/u/takluyver)\
**Post date:** [November 2, 2024, 6:07pm UTC](https://discuss.python.org/t/installer-creation-based-on-distributions/34576/30 "2024-11-02T18:07:10Z")

</div>

> [@oscarbenjamin](#):
>
> Do any of the options above provide this sort of bundling where you just give it the output of `pip freeze` and a directory of wheels?

[Pynsist](https://pynsist.readthedocs.io/en/latest/) (disclaimer: I’m plugging my own tool 😃 ) has a few different ways to get dependencies, but the recommended option where possible is to give it a fully resolved list of packages from PyPI (like the output of `pip freeze`), which it downloads as wheels for you. It’s also possible to point it at extra wheel files in a local directory.

Caveats:

- It treats your own application code rather differently, expecting this as an importable package in the source folder, not a wheel.
- It only makes Windows installers, so if you’re making a cross platform application you still need to figure out something else for Linux & Mac.
  - For Linux, depending on the target audience, I might make a Flatpak (with [this helper tool](https://github.com/flatpak/flatpak-builder-tools/tree/master/pip)), or just give people instructions for pip(x).

- It builds old fashioned executable installers, not the newer `.msi` packages (or have those too been replaced now?)
- I’m not a very good maintainer of Pynsist, since I don’t actually use Windows myself. 🐧

[Previous page](https://discuss.python.org/t/installer-creation-based-on-distributions/34576.md?page=1)
