Questions tagged [zipapp]

This module provides tools to manage the creation of zip files containing Python code, which can be executed directly by the Python interpreter.

This module provides tools to manage the creation of zip files containing Python code, which can be executed directly by the Python interpreter.

21 questions
24
votes
4 answers

python: can executable zip files include data files?

Being fairly new to python I only recently discovered the ability to directly execute a .zip file by placing a __main__.py file at the top of the file. This works great for python code, but can I bundle other types of files and access them with my…
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
7
votes
2 answers

How to make Flask/Jinja2 load bundled templates in an executable zip archive?

I have packaged my Flask web application into an executable Python zipped archive (zipapp). I am having problems with the loading of templates. Flask/Jinja2 is unable to find the templates. To load templates, I used jinja2.FunctionLoader with a…
Flux
  • 9,805
  • 5
  • 46
  • 92
4
votes
1 answer

Distributing an executable zip file with __main__.py, how to access extra data?

I'm doing a little program and I want to distribute it using this recipe: single directory with __main__.py in it zip this directory and adding a shebang on it #!/usr/bin/env python making it executable The problem is that in this package I have…
pygabriel
  • 9,840
  • 4
  • 41
  • 54
3
votes
0 answers

How to use a python zipapp as a kernel in Jupyter Notebook

I have a python env made with a zip app shiv and want to use it for my Jupyter Notebook. I saw a lot of solution with virtual-env, but nothing with a zip app. I tried to create a custom kernel with python3 -m ipykernel install --user…
xrq0
  • 119
  • 13
3
votes
0 answers

Dependency hell with beautifulsoup4 and lxml

I have built a small utility using Python 3.8. Among other things it extracts some data from XML files using beautifulsoup4 and lxml. I use PyCharm and virtualenv for development and my utility works just fine. In order to distribute the util to…
Robert Petermeier
  • 4,122
  • 4
  • 29
  • 37
3
votes
1 answer

What is the correct way to import modules for standalone app created using `python -m zipapp`?

I have a module which I'm going to distribute as standalone app. The module has the following structure: $ tree -L 2 ./ ./ ├── mymodule │ ├── __main__.py │ ├── fun.py └── mymodule.pyz mymodule/__main__.py contains next lines: #!/usr/bin/env…
Ihar Katkavets
  • 1,510
  • 14
  • 25
3
votes
0 answers

How to set import path of a zipapp in Python?

I want to distribute a python app and let user start it with one-click. But even I add path included all depended packages in the app, it will not work unless I move the packages to the top level. The structure works app.zip ├── __main__.py ├──…
PaleNeutron
  • 2,543
  • 4
  • 25
  • 43
2
votes
0 answers

Python zipapp with data files

I created a .pyz application, here is the structure: myapp ┣ templates ┃ ┗ index.j2 ┗ main.py In main program i have this: j2_env = jinja2.Environment(loader=jinja2.FileSystemLoader('templates'), trim_blocks=True) st =…
Gomo55
  • 21
  • 2
2
votes
1 answer

How to load a C dynamic library embedded in a python package with ctypes

I have a python app that, using ctypes, loads and calls a dynamic C library. I want to create a zipapp with this application, but I don't know how to obtain the path to the library from within the app. The directory tree is: mypackage/ ├──…
Dan
  • 2,452
  • 20
  • 45
1
vote
1 answer

How do I compile a Python zipapp as optimized?

Assume the following code under src/app.py: def main(): assert False if __name__ == "__main__": main() Running this using python -o src/app.py will work fine as the assertions are disabled. How can I package a zipapp (python -m zipapp src…
Bharel
  • 23,672
  • 5
  • 40
  • 80
1
vote
1 answer

Why do Python zipapps get slower the bigger they get?

I have a python zipapp (specifically, of pdm). When running from the filesystem, it takes around 0.300s just to show the help page. However, with my zipapp, its 1s. The zipapp is around 25 MB (it includes all of the dependencies). Getting a file in…
DrownedSuccess
  • 123
  • 1
  • 8
1
vote
0 answers

How to access a file resource using importlib.resources when all files are at the root of a folder?

I'm trying to build a python script which then I add to a zip file using python -m zipapp. Everything works fine until it tries to read in my json config file, because it can't find it using directory string like "config.json" (config.json is at the…
u84six
  • 4,604
  • 6
  • 38
  • 65
1
vote
1 answer

ModuleNotFound exception with zipapp and compiled C code

I encounter strange behavior using Python's zipapp feature. Python version: 3.10.5 # these steps come from the docs: https://docs.python.org/3/library/zipapp.html $ mkdir myapp # this is the library I'd like to use $ echo "cysystemd==1.5.3" >…
samba2
  • 468
  • 7
  • 15
1
vote
1 answer

Manage resources in pyz applications

I have a multi-module python application that I have packed in a pyz executable with python3 -m zipapp. I would like to deploy this application with some resources it needs to run (some text files). I have tried to just add these text files to…
Dan
  • 2,452
  • 20
  • 45
1
vote
1 answer

How to bundle httpie with httpie-aws-authv4 into Python zipapp?

It is straightforward to package httpie into a Python "PYZ" (zipapp), e.g. using $ pip install --upgrade zapp $ zapp httpie.pyz httpie.__main__:main httpie $ python ./httpie.pyz --version 1.0.3 Now I tried to include httpie-aws-authv4 as a plug-in…
mgaert
  • 2,338
  • 21
  • 27
1
2