Skip to main content

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:

  • Due to the way that stickytape generates the output file, your script source file should be encoded using UTF-8. If your script doesn’t declare its encoding in its first two lines, then it will be UTF-8 by default as of Python 3.

  • Your script shouldn’t have any from __future__ imports.

  • 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.

Release files for stickytape 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stickytape 0.2.1
File Size Uploaded
stickytape-0.2.1.tar.gz 6.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stickytape 0.2.1
File Interpreter ABI Platform
stickytape-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.4 kB

Release files / stickytape-0.2.1.tar.gz

Download URL stickytape-0.2.1.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9bbdd5dabed633ffde36bb7f656ee0cb55aeae9f87d9c95e377a06bf1ba7df8d
BLAKE2b-256 checksum
How to use checksums
618c59e35d7b75129ad81544c40922b13a9cfff111b67a4e01829044e1080dad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.7

Release files / stickytape-0.2.1-py3-none-any.whl

Download URL stickytape-0.2.1-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
66046dedac42484a352d87c12bc4272e4e222260a41f6e1fcbb29876c018e543
BLAKE2b-256 checksum
How to use checksums
1820d44f0e1acbabcd805e3165d143a37cfd575793082635f62a2180524be180
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.7

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.15

2 release files

0.1.14

2 release files

0.1.13

3 release files

0.1.12

1 release file

0.1.11

1 release file

0.1.10

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page