Solo Development Guide

Advanced Python Bundling

The best way to deploy and run Python code on your Solo is to use the Solo CLI, as described here. This approach uses just two simple commands to package your scripts and their dependencies, uploading the package to Solo, and running the file.

This guide shows the method that was used prior to introduction of Solo CLI packaging. It may be of interest/use to some Solo developers.

Manual bundling

First create and navigate to a new directory on your host computer. This directory will be populated with your own Python scripts and all their dependencies. The entire directory will then be sent to Solo.

Start by creating a virtual environment on your host computer (Linux/Mac OS X):

pip install virtualenv
virtualenv env
source ./env/bin/activate

We want to configure our environment to not compile any C extensions. We can do this simply in our virtual environment with this command:

echo 'import sys; import distutils.core; s = distutils.core.setup; distutils.core.setup = (lambda s: (lambda **kwargs: (kwargs.__setitem__("ext_modules", []), s(**kwargs))))(s)' > env/lib/python2.7/site-packages/distutils.pth

Now you can install Python packages into the new environment using pip install.

When you're ready to move code over to Solo, create a requirements.txt file containing what packages you've installed:

pip freeze > requirements.txt

Next, download these packages on your host computer so they can be moved to Solo along with your code. You can do this by using pip wheel to download them into a new folder (./wheelhouse). Run this command:

pip wheel -r ./requirements.txt --build-option="--plat-name=py27"

This installs all the dependencies in requirements.txt as Python wheel files, which are source code packages.

Next, you can move this entire directory (except for env) over to Solo. The following command shows how to do this using rsync:

rsync -avz --exclude="*.pyc" --exclude="env" ./ root@10.1.1.10:/opt/my_python_code

Install pip on Solo (from the host computer):

solo install-pip

SSH into Solo and install virtualenv:

pip install virtualenv

Finally, navigate to the newly made code directory (/opt/my_python_code) and run these commands:

virtualenv env
source ./env/bin/activate
pip install --no-index ./wheelhouse/* -UI

This requires no Internet connection. Instead, it installs from all the downloaded dependencies you transferred from your computer. You can now run your Python scripts with any packages you depended on, without having impacted any of Solo's own Python dependencies.