Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Step by step setting up python with pip and virtualenv?

Tags:

python

Are there any good step by step tutorials on setting up a Mac to use python, pip and virtualenv setup?

like image 667
Blankman Avatar asked Dec 29 '22 01:12

Blankman


2 Answers

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
like image 189
Matthew Rankin Avatar answered Jan 06 '23 07:01

Matthew Rankin


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!
like image 29
gigimon Avatar answered Jan 06 '23 07:01

gigimon