Python + PIP + Django + Virtualenv

in python •  7 years ago 

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:

Credit: http://www.mahdiyusuf.com/post/5282169518/beginners-guide-easy-install-pip-and-virtualenv-1

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
  1. 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.

  1. Setup your python virtual environment.
virtualenv --no-site-packages mypython
  1. Activate your new environment
 source ./mypython/bin/activate
  1. 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 
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @csgeek! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

You published your First Post
You got a First Vote

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

Upvote this notification to help all Steemit users. Learn why here!