Is there a way to run a python script that is inside a zip file from bash?

前端 未结 2 1601
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-05 01:21

I know there is a way to import modules which are in a zip file with python. I created kind of custom python package library in a zip file.

I would like to put as w

2条回答
  •  天命终不由人
    2021-01-05 02:21

    I finally found a way to do this. If I create a zip file, I must create __main__.py at the root of the zip. Thus, it is possible to launch the script inside the main and call if from bash with the following command :

    python myArchive.zip

    This command will run the __main__.py file! :)

    Then I can create .command file to launch the script with proper parameters.

    You can also put some code in the __main__.py file to give you more flexibility if you need to pass arguments for example.

    ex: python __main__.py buildProject

    The reference documentation is here: https://docs.python.org/2/library/runpy.html

提交回复
热议问题