Skip to main content

Convert Python packages into a single script

Project description

Stickytape can be used to convert a Python script and any Python modules it depends on into a single-file Python script.

Since this relies on correctly analysing both your script and any dependent modules, this may not work correctly in all circumstances. I bodged together the code a long time ago for a specific use case I had, so many normal uses of Python imports are not properly supported. If you need to create a standalone executable from your Python script, I recommend using an alternative such as PyInstaller.

Installation

pip install stickytape

Usage

You can tell stickytape which directories to search using the --add-python-path argument. For instance:

stickytape scripts/blah --add-python-path . > /tmp/blah-standalone

Or to output directly to a file:

stickytape scripts/blah --add-python-path . --output-file /tmp/blah-standalone

You can also point stickytape towards a Python binary that it should use sys.path from, for instance the Python binary inside a virtualenv:

stickytape scripts/blah --python-binary _virtualenv/bin/python --output-file /tmp/blah-standalone

Stickytape cannot automatically detect dynamic imports, but you can use --add-python-module to explicitly include modules:

stickytape scripts/blah --add-python-module blah.util

By default, stickytape will ignore the shebang in the script and use "#!/usr/bin/env python" in the output file. To copy the shebang from the original script, use --copy-shebang:

stickytape scripts/blah --copy-shebang --output-file /tmp/blah-standalone

As you might expect with a program that munges source files, there are a few caveats:

  • Anything that relies on the specific location of files will probably no longer work. In other words, __file__ probably isn’t all that useful.

  • Any files that aren’t imported won’t be included. Static data that might be part of your project, such as other text files or images, won’t be included.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stickytape-0.2.0.tar.gz (6.2 kB view hashes)

Uploaded Source

Built Distribution

stickytape-0.2.0-py3-none-any.whl (8.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page