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
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
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
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
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
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
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
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
Outline
1 VirtualEnvvirtualenvpythonbrewpip
2 DjangoBook Ch2Getting Started
samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 3 / 14
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
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
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
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
VirtualEnv pythonbrew
Pythonbrew
Python version switchVirtualenv supported
1http://pythonbrew.readthedocs.org/en/latest/samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 6 / 14
VirtualEnv pythonbrew
Install pythonbrew
commands$ sudo pip install pythonbrew$ pythonbrew install
samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 7 / 14
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
django ch2
Thank You
Thank You!
samuelololol Brief Introduction to DjangoBook & Virtualenv May 28, 2013 14 / 14