Package code in python

Asked

Viewed 284 times

-2

Ooh, ooh, ooh, ooh, ooh?

So I finished a project that contains only one file. py that imports the following libraries :

dlib face_recognition

And I want to export this code so that OTHER LINUX , only for Linux, can simply download the code and run a "python3 meucodigo.py" and the script runs normally without the need to install all the imported libraries in the code.

Would have as?

Version of the project: Python 3.

1 answer

1

It is possible, but for that, you will have to abandon the status of "a project that contains only one file . py"; you will have to include other things. Fortunately there is a tool for this included from python 3.5, the module zipapp:

The way to use it is as follows:

$ python -m zipapp meucodigo -m "meucodigo:main"

This will generate a file meucodigo.pyz with all libraries you need built in, and can run directly with:

$ python meucodigo.pyz

In the above example the code needs to be in a function called main; Read the documentation for more options.

  • I put everything inside the main function but when I run the command # python3 -m zipapp my.py -m "my:main" returns the error: in-place Editing of Archives is not supported

  • Would you help me by Viewer team please?

  • @Gustavodeoliveira your command is wrong; you should not have .py ali. Read the documentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.