.:. brainsik / jeremy avnet

  • you should follow me
  • Random
  • Archive
  • RSS
  • Ask me anything

Virtualenvs with different interpreters

Update 2011-09-27: Turns out virtualenv and virtualenvwrapper support this out of the box. Most of what’s written below is horrifically complex compared to just using the -p switch when you make your virtualenv. You simply need to do this:

$ mkvirtualenv -p /path/to/some/python coolname

That’ll create a new virtualenv called “coolname” that uses /path/to/some/python for it’s Python interpreter. I’ve tested this with PyPy and it worked great.


A recent comment on the original Virtualenv Burrito announcement asked whether it was possible to create virtualenvs using different Python interepreters. The answer is a cautious: yes!

When virtualenv-burrito installs virtualenv, it prevents the virtualenv command from tying itself to a specific interpreter. I wanted to be able to switch between Python versions, creating virtualenvs for each. I haven’t publicized this feature, nor made it easy to use since there may be hidden pitfalls. That said, I’ve not run into any problems.

The way it works is mkvirtualenv uses the same interpreter invoked by the python command to create the virtualenv. For example, normally when I run mkvirtualenv I get a Python 2.7 environment. Using MacPorts, I can switch from my 2.7 default to 2.6 with:

port select --set python26

Now running mkvirtualenv creates a 2.6 environment.

Regardless of what your current default Python interpreter is, once the virtualenv is made, it stays tied to the Python used during creation.

If you don’t have a nice way to switch your default Python, you can still hack it. The key is making the python command use the interpreter you want.

The following1 will also make a Python 2.6 virtualenv even though 2.7 is the default:

Let me know if it works for you. Especially if you are trying out something other than a CPython!


  1. A new directory is made with a symlink pointing python to the python2.6 executable. When calling mkvirtualenv, the PATH environment is set with this new directory first so the 2.6 interpreter is used. ↩

    • #python
    • #virtualenv
  • 2 years ago
  • 13
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+

Released Virtualenv Burrito 2

This Python breakfast just got tastier. A major update to the way Virtualenv Burrito works was released this weekend. There is now full support for extension points and a less hackish way of managing the packages1 under the hood.

Already have Virtualenv Burrito installed? Run this:

virtualenv-burrito upgrade

New to Virtualenv Burrito? Read about it or run this:

curl -s https://raw.github.com/brainsik/virtualenv-burrito/master/virtualenv-burrito.sh | bash

Virtualenv Burrito’s goal is to have a working virtualenv + virtualenvwrapper environment with just one command. Read about it on Github or see the original announcement.


  1. distribute, virtualenv, and virtualenvwrapper ↩

    • #python
    • #virtualenv
  • 3 years ago
  • 1
  • Permalink
Share

Short URL

TwitterFacebookPinterestGoogle+
Page 1 of 2
← Newer • Older →

Portrait/Logo

Thoughts from a sysadmin turned coder.
  • @brainsik on Twitter
  • brainsik on github

Twitter

loading tweets…

Top

  • RSS
  • Random
  • Archive
  • Ask me anything
  • Mobile
Effector Theme by Pixel Union