Search code examples
python-3.xmacospython-venvdirenv

How to use direnv with python venv?


I have this line in my .envrc

source python3-venv/bin/activate

I basically created a python3 venv inside the folder where the .envrc is located.

However even through the .evnrc is executed (e.g. all now env variables are set correctly when I enter this directoy), the venv is not activated.

When I do which python3, it shows /usr/local/bin/python3 instead of <path to my current folder>/python-venv/bin/python3

If I run the source line manually, the bash prompt will switch to (python3-venv) my-workstation:working-folder antkong$ as expected.

How can I get the python-venv correctly activated?

I am running it in MacOS Mojave.


Solution

  • I removed the venv then rebuild the venv

    python3 -m venv python3-venv
    

    It seems to fix the issue.