I help my clients acquire new users and make more money with their web businesses. I have ten years of experience with SaaS projects. If that’s something you need help with, we should get in touch!
< Back to article list

Using direnv with Python

I have used direnv a couple times, it’s a great way to manage environment variables on a per-directory basis. It nice:

Step 1: Install direnv

The first step is to install direnv on the system:

$ sudo apt-get install direnv
# Is it ok ?
$ direnv --version

Step 2: Configure direnv in a directory

Once direnv is installed, you’ll need to configure it. To do this, you’ll need to create a .envrc file in the root of your project directory. This file will contain the environment variables that you want to set for your project.

For example, if you wanted to set the environment variable FOO to bar, you would add the following line to your .envrc file:

$ echo 'layout python' >> .envrc

Step 3: Activate direnv

Once you’ve created your .envrc file, you’ll need to activate direnv:

$ direnv allow

Now, whenever you enter in this directory you’ll load the python virtual environment.

For more, there is the Wiki