Skip to main content

Using virtualenv with PyPy

Thanks to the work that was recently done on the sys-prefix branch, it is now possible to use virtualenv with PyPy.

To try it, you need:

  • a recent version of PyPy: PyPy 1.3 does not contain the necessary logic to work with virtualenv, so you need a more recent PyPy from subversion trunk. You can either build it by yourself or download one of our precompiled nightly builds
  • a copy of virtualenv-pypy: this is a fork of virtualenv that contains all the patches needed to work with PyPy, and hopefully will be merged back at some point. It should be totally compatible with the official version of virtualenv, so it is safe to use it even to create non-PyPy environments. If you notice some weird behavior that does not happen with the standard virtualenv, please let us know.

The directory layout has been redesigned in a way that it is possible to use virtualenv to install a PyPy both from a precompiled tarball or from an svn checkout:

# from a tarball
$ virtualenv -p /opt/pypy-c-jit-76426-linux/bin/pypy my-pypy-env

# from the svn checkout
$ virtualenv -p /path/to/pypy-trunk/pypy/translator/goal/pypy-c my-pypy-env

Once the environment has been created, you can enter it as usual. Note that bin/python is now a symlink to bin/pypy.

Enjoy it :-)

Comments

René Dudfield wrote on 2010-08-02 17:13:

Another great step for pypy being used in more productions.

Konrad wrote on 2010-08-03 17:50:

Good job!

Alexei Boronine wrote on 2010-08-05 16:22:

I recently made a script called pypyenv for easily installing PyPy in a virtualenv side by side with CPython, sharing site-packages. It will allow one to experiment with PyPy in a working virtualenv without breaking current code.

Antonio Cuni wrote on 2010-08-05 19:16:

@Alex: nice. pypyenv is obviously something different that virtualenv-pypy, but it might be useful if someone wants to try PyPy.

However, I don't think that sharing site-packages is a good idea: it works as long as you have only pure python packages, but it stops as soon as you build some C extension, as the .so produced by PyPy are incompatible with CPython

Alexei Boronine wrote on 2010-08-06 00:58:

@Antonio

Interesting point, I'll mention it in the README. (by the way, thank you for your work, PyPy rocks my socks!)

Xiong Chiamiov wrote on 2010-08-11 23:31:

A bit unrelated, but would it be possible to have nightly releases with consistent filenames? Right now, they all include the svn revision number (I assume that's what it is), which makes it difficult to write a script that downloads and installs the latest version.

Specifically, I'm looking to create an Arch pkgbuild, because it takes too damn long to compile on my notebook, and I don't want to use the stable release.

jezdez wrote on 2010-09-03 15:10:

FYI, the fixes have been merged in virtualenv's main repo.

Anonymous wrote on 2011-12-14 10:28:

it seems there's no pypy/translator/goal/pypy-c anymore?
how to init virtualenv from pypy source now?

Maciej Fijalkowski wrote on 2011-12-14 10:31:

It's not in a checkout you have to compile it first.

Asmo wrote on 2012-04-20 12:47:

Is the information here still valid? Or should virtualenv work fine with pypy?

Maciej Fijalkowski wrote on 2012-04-20 12:50:

Virtualenv should work just fine