pythonvirtualenvpyenvpyenv-virtualenv

Is there a difference between pyenv activate and pyenv local?


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?


Solution

  • 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.