Computer >> Computer tutorials >  >> Programming >> Python

How we can bundle multiple python modules?


Assuming you are using Python 2.6 or later, you could package the scripts into a zip file, add a __main__.py and run the zip file directly. For example, if you zip all files in a file called my_app.zip and place your main script in __main__.py, you can run this zip using python:

$ python my_app.zip

If you want to use a third party script, you can have a look at stickytape module. It can be used to convert a Python script and any Python modules it depends into a single-file Python script. To install stickytape, open your terminal and enter:

$ pip install stickytape

Assuming all your scripts and dependencies reside in the script/sample folder, you can use stickytape in the following way:

$ stickytape scripts/sample --add-python-path . > ./sample-standalone

You can also use the --output-file parameter to give it a file argument:

$ stickytape scripts/sample --add-python-path . --output-file ./sample-standalone