- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
zipapp - Manage executable Python zip archives
The zipapp module has been introduced in Python's standard library since ver 3.5. This module is used to manage the creation of zip files containing Python code, which can be executed directly by the Python interpreter. The module provides both a Command-Line Interface and a programming interface.
To use zipapp module programmatically, we should have a module in which main function is present. The executable archive is built by following command −
python -m zipapp myapp -m "example:main"
Here, the current path should have a folder called myapp. In this folder, there should be example.py which must have main() function.
Create myapp folder and save following code as example.py in it −
def main(): print ('Hello World') if __name__=='__main__': main()
When above command is executed from command terminal, it will create myapp.pyz. We can now execute it from the command prompt.
C:\python37>python myapp.pyz Hello World
Following command line options are supported −
-o <output>, --output=<output>
By default, output file name carries .pyz extension and name as same as the input source. It can be changed by specifying in -o option.
-p <interpreter>, --python=<interpreter>
This is used to explicitly specifying interpreter as the command to run.
Compress files with the deflate method, reducing the size of the output file.
The zipapp module can be used programmatically. It defines the following functions −
Create an application archive from source folder. Additionally, interpreter, target and compressed arguments can be used.
Return the interpreter specified in the #! line at the start of the archive.
>>> import zipapp >>> zipapp.create_archive('myapp.pyz', 'myapp')
- Python import modules from Zip archives (zipimport)
- Work with ZIP archives in Python (zipfile)
- Python zip() Function
- Working with zip files in Python
- How do I make an executable from a Python script?
- Executable Comments in Java
- How to zip a folder recursively using Python?
- How to create a zip file using Python?
- How to zip a Python Dictionary and List together?
- How to Compile a Lua Executable?
- How are files added to a zip file using Python?
- How to create a directly-executable cross-platform GUI app using Python(Tkinter)?
- C# Linq Zip Method
- PHP Zip context options