Friday, 13 October 2023

Activating a pyenv virtual environment with direnv

I use both direnv and pyenv and would like to add something to my .envrc so that whenever I change directory, I also activate my virtual environment with pyenv.

I printed environment variables both when my virtualenv is active and also when it is not. There were a few pyenv variables set, which I added to my .envrc (see below). I was hoping these would activate my pyenv virtual environment upon changing to the directory, but it didn't work.

I'll keep poking at this and trying to sort it out. If I find the answer, I'll update the question with the answer. In the meantime, I'm curious if anyone else has configured direnv so that a virtual environment is loaded upon cd'ing to a directory. If so, would you mind sharing how you did it?

** DID NOT WORK WHEN ADDED TO .envrc**

PYENV_VERSION=ds
PYENV_ACTIVATE_SHELL=1
PYENV_VIRTUAL_ENV=/Users/evan/.pyenv/versions/3.10.4/envs/ds
VIRTUAL_ENV=/Users/evan/.pyenv/versions/3.10.4/envs/ds


from Activating a pyenv virtual environment with direnv

No comments:

Post a Comment