Is there a difference between pyenv activate and pyenv local?

305 Views Asked by At

I know that to activate a virtual environment with pyenv, we can run pyenv activate [virtualenv], but here, i also saw that we can "select" a virtual environment by running pyenv local [virtualenv].

So what is the difference between the two ways?

2

There are 2 best solutions below

2
phd On BEST ANSWER

The base command is pyenv local <python_version>. It selects what Python version to use in the current directory or its subdirectories.

pyenv activate <name> activates a Python virtual environment.

pyenv local <venv-name> works after pyenv virtualenv venv-name and eval "$(pyenv virtualenv-init -)" in shell configuration. After the command the <venv-name> (a virtual environment known to pyenv) is activated when entering (with cd) the directory where pyenv local <venv-name> had been run.

0
ralietonle On

I just found out here that the difference is that this command automatically activates the virtual environment. Thank you!