bash 无法使用 pyenv 激活 virtualenv
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45577194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to activate virtualenv with pyenv
提问by Romulus
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
我正在尝试按照本教程进行操作: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_profile
它包含:
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?
我应该怎么做才能正确启动 virtualenv?
回答by phd
That
那
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
should be in .bashrc
, not .bash_profile
. The latter is executed only by loginshells, the former by all interactive shells.
应该在.bashrc
,不是.bash_profile
。后者仅由登录shell执行,前者由所有交互式 shell 执行。