Integrating direnv with python 3

12 Jun 2020 18:15 direnv python python-3

By now you should be using Python 3.x. You can integrate it with direnv (2.21 or newer) by putting the following in your .envrc

layout pyenv 3.11.1

Note that pyenv needs to be in your PATH. If you installed pyenv by following the instructions from earlier, then do this:

use pyenv
layout pyenv 3.11.1

You’ll need the following in your .direnvrc:

use_pyenv() {
    PATH_add $HOME/.direnv/pyenv/bin

Note that this expects Python to be installed in $HOME/.pyenv/versions, so the python-build instructions need to be changed as follows:

~/.direnv/bin/python-build 3.11.1 ~/.pyenv/versions/3.11.1

And you’re done.