Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to activate virtualenv with pyenv

I run:

pyenv activate new_app 

And 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: https://tutorials.technology/tutorials/59-Start-a-flask-project-from-zero-building-api-rest.html

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/Python.framework/Versions/2.7)   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 -)"; fi 

What should I do to properly start virtualenv?

like image 905
Romulus Avatar asked Aug 08 '17 20:08

Romulus


People also ask

Does Pyenv install virtualenv?

Meet pyenv: a Simple Python Version Management tool. Previously known as Pythonbrew, pyenv lets you change the global Python version, install multiple Python versions, set directory (project)-specific Python versions, and yes create/manage virtual python environments ("virualenv's").

Is Pyenv deprecated?

Is Pyenv deprecated? Deprecated since version 3.6: pyvenv was the recommended tool for creating virtual environments for Python 3.3 and 3.4, and is deprecated in Python 3.6.


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

like image 160
phd Avatar answered Oct 19 '22 12:10

phd