[pypy-dev] Compiling using translate [a small tutorial]

Andrew Evans andrew.rustytub at gmail.com
Sun Feb 5 03:49:12 CET 2012

I thought I would post a small tutorial on using translate.py to compile
pypy RPython scripts

This tutorial is about how to compile python standalone executables using
RPYTHON. RPython is a restricted subset of of python RPython (Restricted
Python) is statically typed

What will we cover in this tutorial is setting up an environment for
building src code in RPython

First you will need to download PyPy and MinGW

(the pypy translator is only available in the source of PyPy we will need
translate.py later to compile the executable. So get the latest source
using Mercurial)

Download Mercurial here *http://mercurial.selenic.com* and install it.
Using Mercurial run this command from your cmd prompt

*hg clone* *https://bitbucket.org/pypy/pypy*

Now you will have PyPy downloaded. I just moved it to the directory C:\pypy
for easy reference. Next we will add an Environment Variable to the
directory containing translate.py it should be in
C:\pypy\pypy\translator\goal\ the file translate.py will be in this goal

Now you will need to install MinGW


Installing the C++ compiler and the MSYS tools also

Add the bin directory of MinGW to your path as well as \msys\1.0\bin; So if
you installed MinGW to to C:\MinGW it would be C:\MinGW\bin and

You will need to use MinGW to compile a dll before we can start. This is so
we can use CTYPES as well MinGW will be our compiler for RPython

Now download the libffi source *http://sourceware.org/libffi/* once again
this will allow for CTYPES in PyPy and MingW

cd to the libffi source directory (you just downloaded) extract it and type
sh ./configure

this will create a dll in .libs in the directory where you extracted the
libffi srcs. The dll will be called:

Next add this to a folder on your C drive and add it to your Environment

Now you should be able to compile source using

*translate.py --cc=mingw32 --output test.exe test.py
Obviously changing directories to where your script is. This was really
only to be a reference for me.

I wrote this originally as a reference for myself last year but I imagine
some one can use it *cheers

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20120204/bc8322c9/attachment.html>

More information about the pypy-dev mailing list