Python + PIP + Django + Virtualenv

For a more through post you probably read this document, this guide was partially based on it, taking
what I find relevant for my usecase:

http://www.cnblogs.com/hellopython/archive/2013/05/21/3089784.html

I'm posting this for my own references and if anyone else finds it useful, all the better.  I keep having to look this up, so having it on my blog seems like a good use of a few minutes of my time.
If you haven't heard of the various tools:

  • pip - awesome tool for installing python related packages. 
  • python-virtualenv  allows you to install python, django and other python libraries with having to pollute your local environment  and avoids the dependency hell that we all know and love.  
  • Django - a rapid development framework similar to ruby on rails but python based.
  • Python - If you're reading this you're probably familiar with the python programming language, but if you're not..FYI.


1.  Install Dependencies
sudo apt-get install python-setuptools python-dev build-essential
2.  Install PIP / VirtualEnv
suggested way of installing it is via:
sudo easy_install -U pip
sudo pip install virtual-env
though if you'd like to use your package manager you can use:
sudo apt-get install python-pip python-virtualenv
The easy_install method is likely to have a more updated version of pip and virtualenv if that matters to you.  These are the tools used to create the environment, not the environment itself.
3. Setup your python virtual environment.
virtualenv --no-site-packages mypython
4.  Activate your new environment
source ./mypython/bin/activate
5.  Install your choice of python libs. 
Most django applications will ship with a requirements.txt which you can pass to pip to install all the dependencies.  The format of this file looks something like this:
Requirements.txt:
Django==1.4
argparse==1.2.1
distribute==0.6.24
heroku==0.1.2
psycopg2==2.4.5
python-dateutil==1.5
requests==0.13.2
wsgiref==0.1.2
docutils
You can use this sample, or simply explicitly list the libs you wanted installed.
pip install django
OR
pip install -r requirements.txt 
That's it.  If you have a django app (for which there about 500 different 101 guides online) you can simply run the usual.
python manage.py syncdb 
python manage.py runserver

from: http://csgeek-random.blogspot.com/2012/12/python-pip-django-virtualenv.html

posted on 2013-05-21 21:17  hellopython  阅读(300)  评论(0编辑  收藏  举报

导航