How to use pyz file?

2.8k Views Asked by At

There is a pyz file that has all the dependency bundle I need (numpy, tensorflow....etc)

I am wondering how do I run a function inside that pyz file.

For example if there is a function called runJob

I would like to call that function in my script

import function_from_pyz
if __name__ == "__main__":
    funciton_from_pyz.runJob()
    

The following doesn't quite work

<python path> my_pyz_file.pyz myscript.py
1

There are 1 best solutions below

0
On

A .pyz file is just a normal zip with a header that allows it to be executed. Python can import modules from a zip file exactly like from a subdirectory.

So, if the function is in a file called __main__.py, you just do:

from my_pyz_file.__main__ import runJob