【发布时间】:2011-02-13 21:11:23
【问题描述】:
有没有关于设置 Mac 以使用 python、pip 和 virtualenv 设置的好的分步教程?
【问题讨论】:
标签: python
有没有关于设置 Mac 以使用 python、pip 和 virtualenv 设置的好的分步教程?
【问题讨论】:
标签: python
下载并安装Python 2.7.1 Mac OS X 64-bit/32-bit x86-64/i386 Installer (for Mac OS X 10.6) 或Python 2.7.1 Mac OS X 32-bit i386/PPC Installer (for Mac OS X 10.3 through 10.6)。
这就是我在 OS X 上安装 virtualenv 和 pip 的方式:
curl -O http://peak.telecommunity.com/dist/ez_setup.py
sudo python ez_setup.py
sudo easy_install pip
sudo pip install virtualenv
我也喜欢将virtualenvwrapper 与virtualenv 一起使用,所以我使用以下方式安装它:
sudo pip install virtualenvwrapper
我最初是从 Jesse Noller 的文章 "SO YOU WANT TO USE PYTHON ON THE MAC?" 中获取这些信息的
~/.bash_profile 设置这可能有点矫枉过正,但下面是我的~/.bash_profile 的 Mac OS X 部分。我使用 Python.org 安装程序安装了多个版本的 Python,这就是我通过 for 循环添加每个版本的 Python 的原因。
# Mac OS X specific settings
if [ ${os_name} == 'Darwin' ]; then
# The last Python added to PATH will be the default Python
PY_VER=( '3.1' '2.6' '2.7')
PY_VER_ELEMENTS=${#PY_VER[@]}
DEFAULT_PY=${PY_VER[${PY_VER_ELEMENTS}-1]}
PY_FW="/Library/Frameworks/Python.framework/Versions"
for (( i=0;i<$PY_VER_ELEMENTS;i++)); do
if [ -x ${PY_FW}/${PY_VER[${i}]}/bin/python${PY_VER[${i}]} ]; then
PATH="${PY_FW}/${PY_VER[${i}]}/bin:${PATH}"
export PATH
fi
done
# Check for virtualenv in the default Python
if [ -x ${PY_FW}/${DEFAULT_PY}/bin/virtualenv ]; then
export VIRTUALENV_USE_DISTRIBUTE=true
export WORKON_HOME=$HOME/.virtualenvs
fi
# Check for pip
if [ -x ${PY_FW}/${DEFAULT_PY}/bin/pip ]; then
export PIP_VIRTUALENV_BASE=$WORKON_HOME
export PIP_REQUIRE_VIRTUALENV=true
export PIP_DOWNLOAD_CACHE=$HOME/.pip_download_cache
fi
# Enable virtualenvwrapper
if [ -x ${PY_FW}/${DEFAULT_PY}/bin/virtualenvwrapper.sh ]; then
source ${PY_FW}/${DEFAULT_PY}/bin/virtualenvwrapper.sh
fi
fi
【讨论】:
~/.bash_profile 的相关部分。
什么问题?
easy-install pip
pip install virtualenv
virtualenv myenv
source myenv/bin/activate 或使用myenv/bin/python
【讨论】: