pythonize
Download, install, and configure Python in one line.
Quickstart
pythonize [--python-version PYTHON-VERSION] [--miniconda]
[--packages PYTHON-PACKAGE [PYTHON-PACKAGE...]]
[--wrapper APPLICATION-NAME]
Fetch and run in one line:
git clone https://github.com/princebot/pythonize.git && pythonize/pythonize
When invoked without options, pythonize uses Continuum's Anaconda to install Python 2.7, conda, pip, and [100+ popular Python packages] (http://docs.continuum.io/anaconda/pkg-docs):
pythonize
Install the latest version of Python 3:
pythonize --python-version 3
Install a specific Python release then add httpie, nose, and click:
pythonize --python-version 3.3 --packages httpie nose click
Overview
pythonize performs unattended download, installation, and configuration for the Anaconda Python distribution and its environment / package manager conda: In one command line, you get a ready-to-use Python preloaded with the libraries you want.
By default, pythonize does this:
- downloads the latest Anaconda,
- installs Anaconda noninteractively,
- adds any additional Python packages you specify,
- sets this new installation as your default Python.
Anaconda Python gives you 100+ popular Python packages beyond the Python
standard library โ but if you want a leaner installation (10x smaller)
including only Python and conda, you can install
Miniconda
instead by using the --miniconda
option.
More than making Python set-up ridiculously easy, pythonize also
facilitates a novel approach to deploying Python applications on Linux and OS X
systems: With the --wrapper
option,
pythonize completely abstracts Python version and library dependencies
from the wrapped application's users.
That means you can code for the Python environment you want. You don't need to grind out kludges for ancient Pythons, add code-clutter for [Python 2/3 compatability] (http://python-future.org/quickstart.html#next-steps), design complex egg / wheel spec files, or leap down the bottomless rabbit hole of freezing or cross-compiling your Python code: Your application just works โ even if your users don't have Python installed at all.
Using Wrapper Mode
To see a Python application wrapped with pythonize in action, use this pseudoโone-liner to fetch and run the demo:
git clone https://github.com/princebot/pythonize.git \
&& pythonize/example_package/example
Invocation
When invoked with the --wrapper
option, pythonize alters its behavior
as follows:
- It skips switching the user's default Python to Anaconda.
- It uses conda to satisfy Python version/library dependencies if conda is already installed rather then creating a fresh installation.
- It always use Miniconda instead of Anaconda.
- It fails rather than merely warns if any items listed with the
--packages
option can't be installed.
Wrapping a Python Application
To make wrapping arbitrary Python programs with pythonize as easy as
possible, this repo contains an example_package
directory with the files
you'll need, already in the recommended layout.
Just follow these steps to get going:
-
Clone this repo:
git clone https://github.com/princebot/pythonize.git
-
Copy the
example_package
directory and rename it for your application. (Note: For the rest of this section, all pathnames will be relative to this directory.) -
Rename the shell wrapper
example
as your main executable (for example,nmapcli
). -
Replace
.runtime/example.py
with your Python program. -
Set your Python program's filename to match your main executable, but add a
.py
extension (for example,nmapcli.py
). -
Edit a couple of variables in
.runtime/wrapper.env
to set your Python dependencies:-
PY_VERSION=<version>
-
PY_PACKAGES=(<package_list>)
-
That's it โ you're done. Your Python app is now pythonized.
Users will run your application the same way they did before, but as an implementation detail, the main executable is now a shell wrapper around your Python program.
The shell wrapper checks that the current execution environment satisfies your expressed dependencies and, if it doesn't, invokes pythonize to fetch the required Python version and/or libraries before running your Python app โ and the end user doesn't have to do a damned thing.
More
To read the full user documentation for pythonize, consult its manual page:
pythonize help
To discover implementation details (including how this can be imported as a shell library and used by other utilities in an OOP-like style), browse the source: it's extensively commented for that purpose.
pythonize has been tremendously useful to me. I've used it as part of bootstrapping cloud and local boxen when golden images were unavailable or nonexistent. I've employed it to package Python apps for sharing with other engineers at work and to run Python admin scripts in wild-west server environments where sane configuration management remains a pipe dream.
I made pythonize mainly to scratch my own itch โ and now I'm sharing it, on the off chance some other people may be itchy, too.
Future Development
There's been more interest in this project than I expected (I wasn't really expecting any, so I was extremely pleasantly surprised to see pythonize listed in the Python Weekly Newsletter).
Because of that, I'm working on a 1.0 release (I consider the current version a beta).
The standout feature of the 1.0 release will be Windows support.
Currently, I plan to implement Windows support via a Windows PowerShell program pythonize.ps1 that I'll add to this repo. I have a strong *nix bias but no Windows antipathy: I just genuinely prefer Linux. However, now that I've been studying the PowerShell documentation in depth, I find it to be a surprisingly amazing control language, and I'm excited about porting the Bash version to it.
When complete, Windows users will be able to use a command similar to this as a quickstart from a PowerShell console (provided they already have Git for Windows):
git clone -q https://github.com/princebot/pythonize; `
if ($?) {.\pythonize\pythonize.ps1}
Depending on other time commitments, I may have this built within a couple of weeks.