一、安装和使用pyenv
参照网址:
http://blog.froehlichundfrei.de/2014/11/30/my-transition-to-python3-and-pyenv-goodby-virtualenvwrapper.html
http://www.cnblogs.com/npumenglei/p/3719412.html
1.安装pyenv 和pyenv virtualenv
git clone git://github.com/yyuu/pyenv.git ~/.pyenv
git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
安装完成后,添加以下代码到~/.zshenv或者~/.zsh_profile,如果没有安装zsh的那么就将以下代码复制到.bash_profile文件中:
# pyenv root
export PYENV_ROOT="$HOME/.pyenv"
# Add pyenv root to PATH
# and initialize pyenv
if [[ -d $PYENV_ROOT ]];then
PATH="$PYENV_ROOT/bin:$PATH"
# initialize pyenv
eval "$(pyenv init -)"
# initialize pyenv virtualenv
eval "$(pyenv virtualenv-init -)"
fi
二、使用:
1.新建一个环境:pyenv virtualenv 3.5.1 Flask
2.设置某个版本的环境:pyenv local Flask
3.如果想要让所有的都是用某一个环境:pyenv activate Flask
4.如果不使用了某一个环境:pyenv deactivate Flask就会换成系统环境了,
5.删除这个虚拟环境:pyenv virtualenv-delete env271
三、问题:
1.更新pyenv的版本:
进入到.pyenv文件夹里面,输入$git pull即可,
更新数据库,pyenv rehash
2.安装python版本问题:
pyenv install 3.6.0
会报一下错误:
Downloading openssl-1.0.2g.tar.gz...
-> https://yyuu.github.io/pythons/b784b1b3907ce39abf4098702dade6365522a253ad1552e267a9a0e89594aa33
Installing openssl-1.0.2g...
BUILD FAILED (OS X 10.11.6 using python-build 1.0.8-2-gb7d89ba)
Inspect or clean up the working tree at /var/folders/jb/x_x_0lz557q8kg81_c5t_9_40000gn/T/python-build.20170303110314.8781
Results logged to /var/folders/jb/x_x_0lz557q8kg81_c5t_9_40000gn/T/python-build.20170303110314.8781.log
Last 10 log lines:
Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.
Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.
这是因为没有配置Xcode的原因:输入:sudo xcodebuild -license accept即可