'Unable to activate virtualenv

I am working on a Macbook Pro running MacOS Monterrey, and I'm following instructions to work in a virtual environment from this site. https://duncanleung.com/set-up-python-pyenv-virtualenv-poetry/

While I am able to create a virtualenv, I am unable to activate it.

On running pyenv activate my-env, I get this error message:

Failed to activate virtualenv.

Perhaps pyenv-virtualenv has not been loaded into your shell properly.
Please restart current shell and try again.

My zshrc file has this content:

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv virtualenv-init -)"

if command -v pyenv 1>/dev/null 2>&1; then
  eval "$(pyenv init -)"
fi
PATH=$(pyenv root)/shims:$PATH

Result of which python:

/Users/abc/.pyenv/shims/python

Result of python -V: Python 3.9.9

What could be possible reasons for the virtualenv not activating?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source