a brief introduction to djangobook and virtualenv

37
Brief Introduction to DjangoBook & Virtualenv Ch2. Getting Started, and virtualenv Samuel Chen, aka. samuelololol May 28, 2013 samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 1 / 14

Upload: samuel-chen

Post on 06-May-2015

2.374 views

Category:

Technology


0 download

DESCRIPTION

A brief introduction to djangobook ch2 and virtualenv/pythonbrew

TRANSCRIPT

Page 1: A brief introduction to djangobook and virtualenv

Brief Introduction to DjangoBook & VirtualenvCh2. Getting Started, and virtualenv

Samuel Chen,aka. samuelololol

May 28, 2013

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 1 / 14

Page 2: A brief introduction to djangobook and virtualenv

Who Am I

Samuel Chen(samuelololol)@TrendMicro2-3 Years in Python

Lab DataCrawler: BeautifulSoupWeb framework: bottle.py

Now: StudyingPyramid/Django

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 2 / 14

Page 3: A brief introduction to djangobook and virtualenv

Who Am I

Samuel Chen(samuelololol)@TrendMicro2-3 Years in Python

Lab DataCrawler: BeautifulSoupWeb framework: bottle.py

Now: StudyingPyramid/Django

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 2 / 14

Page 4: A brief introduction to djangobook and virtualenv

Who Am I

Samuel Chen(samuelololol)@TrendMicro2-3 Years in Python

Lab DataCrawler: BeautifulSoupWeb framework: bottle.py

Now: StudyingPyramid/Django

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 2 / 14

Page 5: A brief introduction to djangobook and virtualenv

Who Am I

Samuel Chen(samuelololol)@TrendMicro2-3 Years in Python

Lab DataCrawler: BeautifulSoupWeb framework: bottle.py

Now: StudyingPyramid/Django

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 2 / 14

Page 6: A brief introduction to djangobook and virtualenv

Who Am I

Samuel Chen(samuelololol)@TrendMicro2-3 Years in Python

Lab DataCrawler: BeautifulSoupWeb framework: bottle.py

Now: StudyingPyramid/Django

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 2 / 14

Page 7: A brief introduction to djangobook and virtualenv

Who Am I

Samuel Chen(samuelololol)@TrendMicro2-3 Years in Python

Lab DataCrawler: BeautifulSoupWeb framework: bottle.py

Now: StudyingPyramid/Django

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 2 / 14

Page 8: A brief introduction to djangobook and virtualenv

Who Am I

Samuel Chen(samuelololol)@TrendMicro2-3 Years in Python

Lab DataCrawler: BeautifulSoupWeb framework: bottle.py

Now: StudyingPyramid/Django

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 2 / 14

Page 9: A brief introduction to djangobook and virtualenv

Outline

1 VirtualEnvvirtualenvpythonbrewpip

2 DjangoBook Ch2Getting Started

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 3 / 14

Page 10: A brief introduction to djangobook and virtualenv

VirtualEnv virtualenv

Virtualenv

Install ‘virtualenv‘ from the package system of the distribution(Linux)Install the package within the ‘virtualenv‘ environmentRun the program in ‘virtualenv‘ environment (development &production)

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 4 / 14

Page 11: A brief introduction to djangobook and virtualenv

VirtualEnv virtualenv

using virtualenv

commands$ virtualenv –note-site-packages 〈env〉$ cd 〈env〉 && source bin/activate(ENV)$ pip install 〈packages〉

–note-site-packagesDo not give access to the global site-packages dir to the virtualenvironment

0http://virtualenvwrapper.readthedocs.org/en/latest/samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 5 / 14

Page 12: A brief introduction to djangobook and virtualenv

VirtualEnv virtualenv

using virtualenv

commands$ virtualenv –note-site-packages 〈env〉$ cd 〈env〉 && source bin/activate(ENV)$ pip install 〈packages〉

activate the virtual environment

0http://virtualenvwrapper.readthedocs.org/en/latest/samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 5 / 14

Page 13: A brief introduction to djangobook and virtualenv

VirtualEnv virtualenv

using virtualenv

commands$ virtualenv –note-site-packages 〈env〉$ cd 〈env〉 && source bin/activate(ENV)$ pip install 〈packages〉

virtualenvwrapper1

$ mkvirtualenv env2(env2)$ workon env1

1http://virtualenvwrapper.readthedocs.org/en/latest/samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 5 / 14

Page 14: A brief introduction to djangobook and virtualenv

VirtualEnv pythonbrew

Pythonbrew

Python version switchVirtualenv supported

1http://pythonbrew.readthedocs.org/en/latest/samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 6 / 14

Page 15: A brief introduction to djangobook and virtualenv

VirtualEnv pythonbrew

Install pythonbrew

commands$ sudo pip install pythonbrew$ pythonbrew install

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 7 / 14

Page 16: A brief introduction to djangobook and virtualenv

VirtualEnv pythonbrew

Install pythonbrew

commands$ sudo pip install pythonbrew$ pythonbrew install

$HOME/.bashrc...[[ -s ¨$HOME/.pythonbrew/etc/bashrc¨ ]]&& source ¨$HOME/.pythonbrew/etc/bashrc

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 7 / 14

Page 17: A brief introduction to djangobook and virtualenv

VirtualEnv pythonbrew

Using pythonbrew

Python Version Switch

commands$ pythonbrew install 2.7.3$ pythonbrew switch 2.7.3$ pythonbrew list$ pythonbrew use 2.7.3

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 8 / 14

Page 18: A brief introduction to djangobook and virtualenv

VirtualEnv pythonbrew

Using pythonbrew

Python Version Switch

commands$ pythonbrew install 2.7.3$ pythonbrew switch 2.7.3$ pythonbrew list$ pythonbrew use 2.7.3

versionSwitched to Python-2.7.3

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 8 / 14

Page 19: A brief introduction to djangobook and virtualenv

VirtualEnv pythonbrew

Using pythonbrew

Python Version Switch

commands$ pythonbrew install 2.7.3$ pythonbrew switch 2.7.3$ pythonbrew list$ pythonbrew use 2.7.3

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 8 / 14

Page 20: A brief introduction to djangobook and virtualenv

VirtualEnv pythonbrew

Using pythonbrew

Python Version Switch

commands$ pythonbrew install 2.7.3$ pythonbrew switch 2.7.3$ pythonbrew list$ pythonbrew use 2.7.3

versionUsing ‘Python-2.7.3‘

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 8 / 14

Page 21: A brief introduction to djangobook and virtualenv

VirtualEnv pythonbrew

Using pythonbrew virtualenv

Virtualenv supported

commands$ pythonbrew venv init$ pythonbrew venv create 〈venv name〉 -p 2.7.3$ pythonbrew venv list$ pythonbrew venv use 〈venv name〉

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 9 / 14

Page 22: A brief introduction to djangobook and virtualenv

VirtualEnv pythonbrew

Using pythonbrew virtualenv

Virtualenv supported

commands$ pythonbrew venv init$ pythonbrew venv create 〈venv name〉 -p 2.7.3$ pythonbrew venv list$ pythonbrew venv use 〈venv name〉

output

Creating ‘〈venv name〉‘ environment into/̃.pythonbrew/venvs/Python-2.7.3

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 9 / 14

Page 23: A brief introduction to djangobook and virtualenv

VirtualEnv pythonbrew

Using pythonbrew virtualenv

Virtualenv supported

commands$ pythonbrew venv init$ pythonbrew venv create 〈venv name〉 -p 2.7.3$ pythonbrew venv list$ pythonbrew venv use 〈venv name〉

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 9 / 14

Page 24: A brief introduction to djangobook and virtualenv

VirtualEnv pythonbrew

Using pythonbrew virtualenv

Virtualenv supported

commands$ pythonbrew venv init$ pythonbrew venv create 〈venv name〉 -p 2.7.3$ pythonbrew venv list$ pythonbrew venv use 〈venv name〉

prompt

(〈venv name〉)$

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 9 / 14

Page 25: A brief introduction to djangobook and virtualenv

VirtualEnv pip

Using pip

pip:https://pypi.python.org/pypi/virtualenv

commands$ (env) pip freeze 〉 requirements.txt$ (env) pip install -r requirements.txtexport PIP DOWNLOAD CACHE2

requirements.txt

(env)$ pip freezeCython==0.16Django==1.4.5...

2stackoverflowsamuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 10 / 14

Page 26: A brief introduction to djangobook and virtualenv

VirtualEnv pip

Using pip

pip:https://pypi.python.org/pypi/virtualenv

commands$ (env) pip freeze 〉 requirements.txt$ (env) pip install -r requirements.txtexport PIP DOWNLOAD CACHE2

requirements.txt

(env)$ pip freezeCython==0.16Django==1.4.5...

2stackoverflowsamuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 10 / 14

Page 27: A brief introduction to djangobook and virtualenv

VirtualEnv pip

Using pip

pip:https://pypi.python.org/pypi/virtualenv

commands$ (env) pip freeze 〉 requirements.txt$ (env) pip install -r requirements.txtexport PIP DOWNLOAD CACHE2

2stackoverflowsamuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 10 / 14

Page 28: A brief introduction to djangobook and virtualenv

django ch2

Install Django

Django BookLink: http://django-book.readthedocs.org/en/latest/chapter02.html

stepsvirtualenvinstall djangoadd .pth filestart projectrunserver (developmentmode)

2.pth: http://www.djangoproject.com/r/python/site-module/samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 11 / 14

Page 29: A brief introduction to djangobook and virtualenv

django ch2

Install Django

Django BookLink: http://django-book.readthedocs.org/en/latest/chapter02.html

stepsvirtualenvinstall django

git trunkpip install django

add .pth filestart projectrunserver (developmentmode)

commands$ git clonehttps://github.com/django/djangodjmaster$ pip install djangotarball: download

2.pth: http://www.djangoproject.com/r/python/site-module/samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 11 / 14

Page 30: A brief introduction to djangobook and virtualenv

django ch2

Install Django

Django BookLink: http://django-book.readthedocs.org/en/latest/chapter02.html

stepsvirtualenvinstall djangoadd .pth filestart projectrunserver (developmentmode)

site-packages/django.pth

/home/user/djmaster

2.pth: http://www.djangoproject.com/r/python/site-module/samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 11 / 14

Page 31: A brief introduction to djangobook and virtualenv

django ch2

Install Django

Django BookLink: http://django-book.readthedocs.org/en/latest/chapter02.html

stepsvirtualenvinstall djangoadd .pth filestart projectrunserver (developmentmode)

command(ENV)$ django-admin.pystartproject mysite

2.pth: http://www.djangoproject.com/r/python/site-module/samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 11 / 14

Page 32: A brief introduction to djangobook and virtualenv

django ch2

Install Django

Django BookLink: http://django-book.readthedocs.org/en/latest/chapter02.html

stepsvirtualenvinstall djangoadd .pth filestart projectrunserver (developmentmode)

mysite—– manage.py—– mysite

init .pysettings.pyurls.pywsgi.py

2.pth: http://www.djangoproject.com/r/python/site-module/samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 11 / 14

Page 33: A brief introduction to djangobook and virtualenv

django ch2

Install Django

Django BookLink: http://django-book.readthedocs.org/en/latest/chapter02.html

stepsvirtualenvinstall djangoadd .pth filestart projectrunserver (developmentmode)

(ENV)$ python manage.pyrunserver

mysite—– manage.py—– mysite

init .pysettings.pyurls.pywsgi.py

2.pth: http://www.djangoproject.com/r/python/site-module/samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 11 / 14

Page 34: A brief introduction to djangobook and virtualenv

django ch2

Install Django

Django BookLink: http://django-book.readthedocs.org/en/latest/chapter02.html

stepsvirtualenvinstall djangoadd .pth filestart projectrunserver (developmentmode)

commands(ENV)$ python manage.pyrunserver 8080(ENV)$ python manage.pyrunserver 0.0.0.0:8080

2.pth: http://www.djangoproject.com/r/python/site-module/samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 11 / 14

Page 35: A brief introduction to djangobook and virtualenv

django ch2

database packages

PostgreSQL: psycopg, psycopg23

SQLite3: default supportedMySQL: mySQLdb4

Oracle: cx Oracle5

3http://www.djangoproject.com/r/python-pgsql/4http://www.djangoproject.com/r/python-mysql/5http://cx-oracle.sourceforge.net/

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 12 / 14

Page 36: A brief introduction to djangobook and virtualenv

django ch2

folder and files

django-admin.pymysite/manage.pymysite/ init .pymysite/settings.pymysite/url.pymysite/wsgi.py

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 13 / 14

Page 37: A brief introduction to djangobook and virtualenv

django ch2

Thank You

Thank You!

samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 14 / 14