开发者

Step by step setting up python with pip and virtualenv?

开发者 https://www.devze.com 2023-02-10 11:36 出处:网络
Are there any good step by step tutorials on setting up a Mac to use python, 开发者_Python百科pip and virtualenv setup?Download and install the Python 2.7.1 Mac OS X 64-bit/32-bit x86-64/i386 Installe

Are there any good step by step tutorials on setting up a Mac to use python, 开发者_Python百科pip and virtualenv setup?


Download and install the Python 2.7.1 Mac OS X 64-bit/32-bit x86-64/i386 Installer (for Mac OS X 10.6) or Python 2.7.1 Mac OS X 32-bit i386/PPC Installer (for Mac OS X 10.3 through 10.6).

Instructions for installing virtualenv and pip on OS X

This is how I installed virtualenv and pip on OS X:

curl -O http://peak.telecommunity.com/dist/ez_setup.py
sudo python ez_setup.py
sudo easy_install pip
sudo pip install virtualenv

I also like to use virtualenvwrapper with virtualenv, so I installed it using:

sudo pip install virtualenvwrapper

I originally picked up this information from Jesse Noller's article "SO YOU WANT TO USE PYTHON ON THE MAC?"

~/.bash_profile Settings

This is probably overkill, but below is the Mac OS X section of my ~/.bash_profile. I have multiple versions of Python installed using the Python.org installers, which is why I go through the for loop to add each version of 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


What problems?

  1. Install PIP: easy-install pip
  2. Install virtualenv: pip install virtualenv
  3. Create a virtualenv environment: virtualenv myenv
  4. Enter to environment: source myenv/bin/activate or use myenv/bin/python
  5. ???
  6. PROFIT!
0

精彩评论

暂无评论...
验证码 换一张
取 消