• Stars
    star
    190
  • Rank 203,739 (Top 5 %)
  • Language
    Python
  • License
    Other
  • Created about 11 years ago
  • Updated almost 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A fork of cpython that supports building a static interpreter and true standalone executables

Static-Python

This is a fork of the official Python hg repository with additional tools to enable building Python for static linking.

You may be wondering, "why would you want to do that? After all, static linking is evil." Here are a few possible reasons:

  • To run Python programs on other machines without requiring that they install Python.

  • To run Python programs on other machines without requiring that they have the same versions of the same libraries installed that you do.

  • Because the major binary distribution tools for Python (cx_Freeze, bbfreeze, py2exe, and py2app) ship in a way that the Python source code can be trivially derived (unzip the archive of .pyc files and decompile them.) For proprietary or security-conscious applications, this is unacceptable.

Usage

Building Static Python

To build a static Python executable and library, check out the appropriate branch (either 2.7, 3.3, or master) and run the following command:

make -f Static.make

This will create an executable called python in the working directory, and a static library, libpythonX.X.a, in the install/lib directory. You can confirm that this executable is not dependent on any shared libraries using ldd python which should report that python is not a dynamic executable. However, by default this executable's functionality will be very limited - it won't even be able to access most modules from the Python standard library.

In order to make this Python interpreter truly standalone (not dependent on installed Python modules), you can designate Python modules to be compiled as builtins, which will be statically linked into the Python interpreter. Static.make generates a file in Modules/Setup which needs to be edited to specify these new builtin modules.

You can automatically add builtins when building Static Python by passing BUILTINS and/or SCRIPT variables to Static.make, e.g.:

make -f Static.make BUILTINS="math zipfile zlib" SCRIPT="/path/to/script.py"

Each module listed in the BUILTINS variable will be added, if possible. SCRIPT can be used to specify the path to a Python script. This script will be scanned for dependencies using modulefinder, and all dependencies will be added as builtins if possible (not the script itself - it should be compiled using static_freeze.py and linked to the resulting static library.) Finally, if the DFLAG variable is set to "-d", all dependencies of all modules will be automatically added as well (this will usually include many modules, and you may not really need them all.)

(If you previously built Static Python, you should make -f Static.make clean first. Also, this step requires an existing Python installation, preferably of the same version you're building, so you may need to build and install Python the normal way first before building it statically..)

Adding builtins can also be done manually by editing Modules/Setup. Add lines to the end of the file in the format:

module_name module.c ...

These .c files can be generated from .py files using Cython:

cython module.py

(This is done automatically using add_builtins.py, the script called by Static.make when BUILTINS or SCRIPT are supplied.)

Packages are not currently supported. I'm working on an automatic solution for compiling and including packages. Stay tuned.

Compile a standalone executable

Once you've compiled a static Python library, you can turn a Python script into a standalone executable using the static_freeze.py script.

Tools/static_freeze/static_freeze.py test.py libpython2.7.a

This will generate an executable called "test" in the working directory, which is not dependant on any shared libraries, Python modules, or the Python interpreter!

Acknowledgements

Major thanks to Gabriel Jacobo who pioneered this method: http://mdqinc.com/blog/2011/08/statically-linking-python-with-cython-generated-modules-and-packages/

More Repositories

1

spinehaxe

Spine runtime for Haxe 3. Based on current AS3/libgdx runtimes.
Haxe
64
star
2

hxpk

Haxe port of the libGDX Texture Packer
Haxe
46
star
3

scotch

The Scotch programming language
Haskell
44
star
4

krit-kit

[deprecated] 2D game engine, written in Kit, using SDL/OpenGL. See more recent C++ version at https://github.com/bendmorris/krit
Kit
17
star
5

hide-n-stab

Multiplayer stealth action game. Created in 48 hours for Ludum Dare 29, "beneath the surface."
Haxe
17
star
6

taxiphy

Common repository for scripts to generate trees from taxonomies. Currently includes ITIS, NCBI, and GBIF.
Python
16
star
7

krit

2D game engine in C++. Sharing but this is mostly for personal use - once a project has been released I'll update the documentation and make it more user friendly :) Bear with me!
C++
14
star
8

staticdata

Haxe library for managing rich static data
Haxe
13
star
9

haxepop

An enhanced fork of HaxePunk 2.6
Haxe
10
star
10

python-phylopic

Simple Python phylopic.org wrapper
Python
9
star
11

neskit

NES emulator written in Kit
Kit
9
star
12

pybioclim

A Python interface to BIOCLIM climate data. Data files included in package.
C
8
star
13

python-geocode

Simple Python geocoding module using the Google Maps API with automatic result caching
Python
8
star
14

waxwing

JS-to-JS optimizing compiler
TypeScript
8
star
15

pyj2d

Pygame for Jython. Originally forked from James Garnon: http://gatc.ca/projects/pyj2d/
Python
8
star
16

pyhx

Python import hook for Haxe
Python
8
star
17

beaver

Beaver, an experimental semantic programming language for processing data in the form of triple graphs.
Python
6
star
18

hxbehave

Haxe behavior trees
Haxe
6
star
19

gun-violence

Do higher rates of gun ownership predict higher rates of gun violence?
Python
5
star
20

hxconf

Haxe INI-style sectioned config file parser
Haxe
4
star
21

swc_databases

Material from Software Carpentry SQL databases session. Originally developed for U. Virginia workshop Mar 7-8 2013.
Python
4
star
22

pphp

PHP AST transformation extension
Shell
4
star
23

rdf-treestore

A phylogenetic tree store with an RDF backend
Python
4
star
24

hungryhungryspiders

Hungry Hungry Spiders! (LD45)
Haxe
3
star
25

pagefile

Haxe storage paging system
Haxe
3
star
26

tax_resolve

Some wrapper functions for acquiring standardized forms of taxonomic names.
Python
3
star
27

lscolumns

pretty-print columns of data
Python
3
star
28

as3hx

Convert AS3 code to Haxe. Updated to work on Haxe 3.
Nemerle
3
star
29

jython-pgu

A fork of the Python Game Utilities refactored to run on Jython using pyj2d
Python
3
star
30

bmfg

CLI BMFont-compatible BitMap Font Generator
Python
3
star
31

neon_portal

Django web app for data entry into the dodobase system.
Python
3
star
32

markdown-doc

A template for writing articles, proposals, etc. in Markdown with pandoc and bibtex
3
star
33

2013-12-12-glasgow

Software Carpentry workshop in Glasgow, 12/12/2013
Python
2
star
34

ncbi_taxonomy

Build a Newick tree from the NCBI taxonomy
Python
2
star
35

hxgit

Simple way to build a project with Git version info
Haxe
2
star
36

grumpkin

Asynchronous Haxe server framework
Haxe
2
star
37

inkscape_split

Split Inkscape SVG into one PNG per layer
Python
2
star
38

biophylo

Phylogenetic computing library for Haskell
Haskell
2
star
39

streets-of-style

Ludum Dare 41: Combine 2 Incompatible Genres
Haxe
2
star
40

haxe-redis

Haxe
2
star
41

phylolabel

Automatic labeling of higher-order taxa in a phylogeny using a reference taxonomy
Python
2
star
42

autoesg2

Tool for downloading CMIP5 data from ESG server
Python
2
star
43

alpha_bandaid.py

Stops alpha bleeding by filling transparent pixels with the color value of the closest visible pixel.
Python
2
star
44

thegarden

Ludum Dare 30, "Connected Worlds"
Haxe
2
star
45

water_maker

Make an animated water spritemap from a square water tile.
Python
1
star
46

bbs_cooccurrence

Python
1
star
47

rubenwriter

A fullscreen app for Ruben to type letters and numbers on my laptop without being able to minimize, quit, or do anything else.
Python
1
star
48

rust-hangman

Hangman, in Rust, for fun
Rust
1
star
49

make_tutorial

SWC Introduction to Make
Python
1
star
50

mapreduce-hw

Learning how to use mapreduce on hadoop
Python
1
star
51

krit-toolchain

Dependencies and headers
C
1
star
52

HaxePunk-layout

Simple layout and UI library for HaxePunk
Haxe
1
star
53

odum

Final project for course on Big Data (Information and Library Science, UNC) - uses MapReduce to find similar studies from social science data
Python
1
star
54

autoesg

Open source tool for downloading climate data from the Earth System Grid automatically.
Python
1
star
55

pssat

Protein Secondary Structure Alignment Tool - performs a probabilistic alignment of predicted secondary structures, and generates HTML output. Written in Haskell.
Haskell
1
star
56

rosalind

rosalind.info solutions
Python
1
star
57

pyscotch

Implementation of Scotch programming language in Python
Python
1
star
58

itis_taxonomy

Build a Newick tree from the ITIS taxonomy
Python
1
star
59

cql

Parser for the Contextual Query Language (CQL)
Python
1
star
60

LD37

Ludum Dare 37 48 hour competition - "One Room"
Haxe
1
star
61

haxepop-ui

A simple, flexible UI framework for the Haxepop game engine
Haxe
1
star
62

spine-krit

Kit/Krit Spine renderer
Kit
1
star
63

catalyst-demo

JavaScript
1
star
64

fia_spatial_diversity

Quantifying the contributions of selection, dispersal, and drift to spatial diversity of tree communities.
Python
1
star
65

soupdb

WIP
Rust
1
star
66

tile_padder

Add padding + alpha color correction to tilesets to avoid bleeding and tearing
Python
1
star
67

swc-materials

SWC teaching materials
Python
1
star
68

adelaide_swc

Python
1
star
69

ache

An asset pipeline automation tool.
Python
1
star
70

richness_scale

Python
1
star
71

family-twine

Family Twine projects
HTML
1
star
72

mgrast

Simple tool for downloading lots of metagenomes from MG-RAST for microbial macroecology
Python
1
star
73

bendmorris.github.io

Personal website
JavaScript
1
star
74

swc-shell

Python
1
star
75

leek

highly available distributed celerybeat scheduler
Python
1
star
76

2016-dem-primary-analysis

Python
1
star
77

aur

Download, build, and install packages from the Arch User Repository (AUR)
Shell
1
star
78

Gitview

js widget to list github repositories
JavaScript
1
star
79

waxwing-phylogeography

Phylogeography of cedar and bohemian waxwings, and comparison to silky flycatchers. From a class project.
Python
1
star
80

picoides-phylogeography

Files from a project that I started and set aside - might be useful in the future
Python
1
star