autovenv: virtualenv with less hassle

I don’t want to be a product of my environment, I want my environment to be a product of me.

—Frank Costello in The Departed

Virtual environments are great, but they can be a bit annoying to create, manage, and switch between. It gets even worse when multiple different python versions come into play. autovenv takes the annoyance away.

(Author’s note: I wrote this package for my own use. It hasn’t been publicly released for long so very much qualifies as alpha software, but hopefully you find it as handy as I do! It would be cool if you’d try it out. Issues/pull requests/etc would be even cooler).

Basically, as long as there’s a requirements.txt file in your python project, autovenv will figure out that the folder you’re in is a python project, create a virtualenv for that project automatically, and activate/deactivate that virtualenv when you cd in/out of the project folder.

If you want to use a different python from your system python, autovenv helps with that too, by allowing you to build any of the different python versions out there, and use them with your virtualenvs.

How it Works

Just cd to anywhere within a python project, and autovenv will create a virtual environment for you if you don’t have one already, and activate it:

 alex@xyz:~$ cd pyprojects/skynet
 AUTOVENV: creating virtual environment: skynet
 New python executable in /home/alex/.virtualenvs/skynet/bin/python
 Installing setuptools, pip, wheel...done.
 Requirement already up-to-date: pip in ...

cd to a different project, it’ll switch virtual environments automatically. cd out of a project and it’ll deactivate the virtual environment.

autovenv tries to keep things tidy by storing the virtualenvs it creates under ~/.virtualenvs


Simply install with pip globally, ie not within a virtual environment:

$ pip install autovenv

and then add the following line to the end of your .bashrc file:

source `which`

That’s it!

When building python versions, you may need to install some development packages on your system. If you’re using apt-get with the Ubuntu repositories, this command may help:

$ sudo apt-get install build-essential zlib1g-dev libbz2-dev libssl-dev libreadline-dev libncurses5-dev libsqlite3-dev libgdbm-dev libdb-dev libexpat-dev libpcap-dev liblzma-dev libpcre3-dev