Recent Entries »

Converting an IPython Notebook to PDF

If you have an IPython Notebook (*.ipynb file), you may want to convert to PDF for distribution. If you read the documentation for ipython nbconvert, it seems fairly straightforward:

$ ipython nbconvert --to PDF <your notebook>.ipynb

However, if you run that, you’re likely to run into an error asking to you install Pandoc; this is because nbconvert relies on an intermediate conversion to LaTeX first, and then to the final PDF output. Pandoc is used for this. To install on OS X:

$ brew install pandoc

Running the conversion again yields another error, suggesting you need the pdflatex command; Pandoc doesn’t include any built-in support for LaTeX->PDF, so you’ll need a LaTeX install. The Pandoc documentation suggests BasicTeX:

$ brew cask install basictex

Trying conversion results in another failure. Turns out, you need to install some more LaTeX packages:

$ sudo tlmgr update --self
$ sudo tlmgr install adjustbox
$ sudo tlmgr install collectbox
$ sudo tlmgr install ucs

After this, you should be able to do your conversion and have a fairly-decent PDF output based on your IPython Notebook:

$ ipython nbconvert --to PDF <your notebook>.ipynb

Remote Python debugging using PyDev/LiClipse for OpenStack Swift

We all know what debugging is – stepping through running code, line by line, inspecting variables and trying to figure out what’s wrong with your program while simultaneously tearing your hair out. However, usually when debugging Python code, the Python process is running locally on your system. What happens if you want to debug through code running on another server?

This is typically the case when working with OpenStack Swift, since the Swift-all-in-one (SAIO) instructions tell you to use a VM to run your Swift installation in, and a Vagrant VM provided by SwiftStack simplifies this. However, this means that the Swift code is not running locally; it’s running inside of your VM – so how do you debug into it?

Remote debugging aims to solve this by allowing you to inspect, trace and step through code running in a Python process on another machine. Setting this up requires some work, but is well worth the effort when debugging a non-trivial application running on a remote server or VM.


Accessing the host file system from a Docker container on OS X or Windows

Mounting (or sharing) a directory from the Docker daemon host into a container is simple enough. Example:

$ docker run -v [host directory path]:[container directory path] -it [image name]

However, on OS X and Windows, the Docker daemon (currently) runs inside of a Linux VM, that by default is run using VirtualBox. (Since Docker only runs natively on Linux) So, you’d be mounting a folder from the Linux VM, which is probably not what you want if you want to share files from your host machine into the container.