根据 这篇文章, 学习flask前要先装一下virtualenv
安装virtualenv和virtualenvwrapper
sudo pip install virtualenv
sudo pip install virtualenvwrapper
安装后还不能使用, 默认virtualenvwrapper安装在/usr/local/bin下, 打开下面的 virtualenvwrapper.sh, 会看到Setup,内容如下:
Setup:
1. Create a directory to hold the virtual environments.
(mkdir $HOME/.virtualenvs).
2. Add a line like "export WORKON_HOME=$HOME/.virtualenvs"
to your .bashrc.
3. Add a line like "source /path/to/this/file/virtualenvwrapper.sh"
to your .bashrc.
4. Run: source ~/.bashrc
5. Run: workon
6. A list of environments, empty, is printed.
7. Run: mkvirtualenv temp
8. Run: workon
9. This time, the "temp" environment is included.
10. Run: workon temp
11. The virtual environment is activated.
如果碰到权限问题,可以看这个答案:http://stackoverflow.com/questions/21194519/cant-use-mkvirtualenv-site-packages-markerlib-permission-denied
需要执行
sudo chown -R your-username:wheel /Library/Python/2.7/site-packages
执行一下在虚拟环境下执行pip --version, 看看pip所在的目录是不是虚拟环境的目录,如果不是,在.bashrc中加入如下:
# pip should only run if there is a virtualenv currently activated
export PIP_REQUIRE_VIRTUALENV=true
# cache pip-installed packages to avoid re-downloading
export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache
网友评论