I run:
pyenv activate new_appAnd I get:
Failed to activate virtualenv.
Perhaps pyenv-virtualenv has not been loaded into your shell properly.
Please restart current shell and try again.I am trying to follow this tutorial:
Other info:
bash-3.2$ python --version
Python 3.6.0
bash-3.2$ pyenv version
3.6.0 (set by /Users/me/Projects/flask_api/.python-version)
bash-3.2$ pwd
/Users/me/Projects/flask_api
bash-3.2$ pyenv versions system 3.5.1 3.5.1/envs/my_env_3_5_1
* 3.6.0 (set by /Users/me/Projects/flask_api/.python-version) 3.6.0/envs/new_app flask_app my_env_3_5_1 new_app
bash-3.2$ virtualenv --version
15.1.0
bash-3.2$ pyenv virtualenvs
3.5.1/envs/my_env_3_5_1 (created from /Users/me/.pyenv/versions/3.5.1) 3.6.0/envs/new_app (created from /Users/me/.pyenv/versions/3.6.0) flask_app (created from /System/Library/Frameworks/) my_env_3_5_1 (created from /Users/me/.pyenv/versions/3.5.1) new_app (created from /Users/me/.pyenv/versions/3.6.0)I recently made my .bash_profile it contains:
bash-3.2$ cat ~/.bash_profile
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
exec "$SHELL"
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fiWhat should I do to properly start virtualenv?
5 Answers
That
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"should be in .bashrc, not .bash_profile. The latter is executed only by login shells, the former by all interactive shells.
Within ~/.zshrc file:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
export PYENV_VIRTUALENV_DISABLE_PROMPT=1
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"Sadly the eval lines alone (as mentioned in the pyenv and pyenv-virtualenv instructions) did not work for me.
- Add the lines below to your
~/.bash_profileor~/.zprofile
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"- Restart shell or run the command:
source ~/.bash_profileNote:
If you are using zsh shell (default for macOS Catalina and/or Big Sur) you have to use ~/.zprofile file rather than ~/.bash_profile
For me the below fixed my problem. I am using MacBook Pro thanks @Kalanos
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)" For mac users!
Make sure you have installed pyenv and pyenv-virtualenv using brew
If you're default shell is set to bash, add the following lines to your .bashrc by opening shell and enter,
nano ~/.bashrcthen add :
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv virtualenv-init -)"then pressCtrl + O and Enter and Ctrl + X to save changes!