Mike Grouchy

Ambitious Python Developer, Beer drinker and lover of all things basketball.

Setting up PyPy 1.9 on OSX


pypy

As I had said before on this blog, I sometimes use it as a way to record things I want to remember. This is one of those times.

I have started a new project that uses PyPy and while there is documentation out there to get started, I find it useful to have it all in the same place and not spread around.

What is PyPy

PyPy is Python interpreter and JIT compiler. The latest PyPy release PyPy 1.9, the one we are installing, is CPython 2.7.2 compatible. PyPy is focused on speed and 100% compatibility with the CPython.

Installing PyPy

There are a couple of options to install PyPy on OSX.

I like to manage my packages using Homebrew when thats an option, so I installed using Homebrew. It was very easy to get setup just

    brew install PyPy

Then follow any instructions in your terminal.

You should then see a symlink in your /usr/local/bin directory for PyPy

    ~ >> ls /usr/local/bin | grep pypy
    pypy

And assuming you have homebrew setup correctly you should be able to type "pypy" in your terminal and get an interactive interpreter.

    ~ >> pypy
    Python 2.7.2 (341e1e3821ff, Jun 07 2012, 15:42:54)
    [PyPy 1.9.0 with GCC 4.2.1] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    And now for something completely different: ``it's beautiful: very rectangular
    and yellow''
    >>>>

If you have gotten this far you have been successful at installing PyPy!

Now, like any good pycoder, lets move on to getting PyPy setup inside a Virtualenv.

Getting PyPy to work with Virtualenv or Virtualenvwrapper

Luckily getting PyPy set up in a virtualenv is really easy, for virtualenv the command is:

    virtualenv -p /usr/local/bin/pypy environmentname

for Virtualenvwrapper, its basically the same:

    mkvirtualenv -p /usr/local/bin/pypy environmentname

In the output of each of these commands you should see:

    Running virtualenv with interpreter /usr/local/bin/pypy
    New pypy executable in testpypy2/bin/pypy
    Installing setuptools............done.
    Installing pip...............done.

Now you can activate your environment.

In virtualenv:

    source /path/to/your/virtualenv/bin/activate

In virtualenvwrapper:

    workon environmentname

And test your Python version:

    python --version
    Python 2.7.2 (341e1e3821ff, Jun 07 2012, 15:42:54)
    [PyPy 1.9.0 with GCC 4.2.1]

Now you are good to get working on your Python project with PyPy. Happy hacking!

blog comments powered by Disqus