Rom*_*lus 17 python bash virtualenv pyenv
我跑:
pyenv activate new_app
Run Code Online (Sandbox Code Playgroud)
我得到:
Failed to activate virtualenv.
Perhaps pyenv-virtualenv has not been loaded into your shell properly.
Please restart current shell and try again.
Run Code Online (Sandbox Code Playgroud)
我正在尝试遵循本教程:https://tutorials.technology/tutorials/59-Start-a-flask-project-from-zero-building-api-rest.html
其他信息:
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)
Run Code Online (Sandbox Code Playgroud)
我最近把.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
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能正确启动virtualenv?
Has*_*tax 77
~/.zshrc文件内:
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 -)"
Run Code Online (Sandbox Code Playgroud)
遗憾的是,仅这些eval行(如 pyenv 和 pyenv-virtualenv 说明中所述)对我不起作用。
phd*_*phd 35
那
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Run Code Online (Sandbox Code Playgroud)
应该在.bashrc,而不是.bash_profile.后者仅由登录 shell 执行,前者由所有交互式shell执行.
Sli*_*eam 22
~/.bash_profile或~/.zprofileeval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Run Code Online (Sandbox Code Playgroud)
source ~/.bash_profile
Run Code Online (Sandbox Code Playgroud)
如果您使用的是zsh shell(macOS Catalina和/或Big Sur 的默认设置),则必须使用~/.zprofilefile 而不是~/.bash_profile
小智 9
对我来说,以下内容解决了我的问题。我正在使用 MacBook Pro 谢谢@Kalanos
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9522 次 |
| 最近记录: |