{"id":35,"date":"2012-08-31T16:19:54","date_gmt":"2012-08-31T20:19:54","guid":{"rendered":"http:\/\/www.mbeckler.org\/blog\/?p=35"},"modified":"2016-08-11T10:34:15","modified_gmt":"2016-08-11T14:34:15","slug":"installing-django-on-ubuntu-12-04","status":"publish","type":"post","link":"https:\/\/www.mbeckler.org\/blog\/?p=35","title":{"rendered":"Installing Django on Ubuntu 12.04"},"content":{"rendered":"<p>Notes for myself so I can do this again someday&#8230; (UPDATE: I had to refresh the links at the bottom of this article to the latest version of Django. Good luck.)<\/p>\n<p>Let&#8217;s say we are working on a Django project called <strong>applesauce<\/strong>, for lack of a better name. We start by creating a directory for this project:<br \/>\n<code>cd ~<br \/>\nmkdir applesauce<br \/>\ncd applesauce<\/code><\/p>\n<p>We use <strong>pip<\/strong> to install python packages, so we must install it first:<br \/>\n<code>sudo apt-get install python-pip python-setuptools<\/code><\/p>\n<p>We use <strong>virtualenv<\/strong> to manage our python environment to make sure we don&#8217;t go too crazy. We can use pip to install it:<br \/>\n<code>sudo pip install virtualenv<\/code><\/p>\n<p>virtualenv has this idea of using a directory to store its settings, so let&#8217;s make one for it, and use it as a new virtual environment:<br \/>\n<code>mkdir applesauce-virtualenv<br \/>\nvirtualenv applesauce-virtualenv<\/code><\/p>\n<p>The &#8211;no-site-packages is the default now, so we don&#8217;t include it here (you could, but it&#8217;s deprecated). This helps keep things sane.<\/p>\n<p>virtualenv creates a shell script for you to source that sets up the necessary environment variables. You will need to source this file every time you want to work on this project:<\/p>\n<p><code>source applesauce-virtualenv\/bin\/activate<\/code><\/p>\n<p>You should see that your shell prompt has changed, and now has &#8220;(applesauce-virtualenv)&#8221; at the front of the prompt. This lets you know that you have already &#8220;logged in&#8221; to your virtualenv.<\/p>\n<p>Now, let&#8217;s install some of the packages required to work with Django. We start with the non-python system-wide packages and libraries:<br \/>\n<code>sudo apt-get install libxml2-dev libxslt1-dev python2.7-dev libpng12-dev libfreetype6-dev build-essential python-dev<\/code><\/p>\n<p>Then, make sure that you are in your virtual environment and install these python things using pip. Since we&#8217;re installing these packages into the virtualenv we don&#8217;t need to use sudo.<\/p>\n<p><code>pip install django django-debug-toolbar south httplib2 lxml<\/code><\/p>\n<p>If you have any modules\/packages that you want to be able to use in your Django project, you can copy them into applesauce-virtualenv\/lib\/python2.7\/site-packages\/<\/p>\n<p>To verify that Django can be seen by Python, type <strong>python<\/strong> from your shell. Then at the Python prompt, try to import Django:<\/p>\n<p><code>>>> import django<br \/>\n>>> print django.get_version()<br \/>\n1.4.1<\/code><\/p>\n<p>Now, you can start working with Django. You might want to start with the official tutorial, <a href=\"https:\/\/docs.djangoproject.com\/en\/1.10\/intro\/tutorial01\/\">Writing your first Django app<\/a>.<\/p>\n<p>(Some information taken from the <a href=\"https:\/\/docs.djangoproject.com\/en\/1.10\/intro\/install\/\">Django Quick install guide<\/a>.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Notes for myself so I can do this again someday&#8230; (UPDATE: I had to refresh the links at the bottom of this article to the latest version of Django. Good luck.) Let&#8217;s say we are working on a Django project called applesauce, for lack of a better name. We start by creating a directory for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[17,10,18,20,16,21,19],"class_list":["post-35","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-django","tag-linux","tag-pip","tag-programming","tag-python","tag-sysadmin","tag-virtualenv"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2BznB-z","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.mbeckler.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/35","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mbeckler.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mbeckler.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mbeckler.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mbeckler.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=35"}],"version-history":[{"count":7,"href":"https:\/\/www.mbeckler.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/35\/revisions"}],"predecessor-version":[{"id":338,"href":"https:\/\/www.mbeckler.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/35\/revisions\/338"}],"wp:attachment":[{"href":"https:\/\/www.mbeckler.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=35"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mbeckler.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=35"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mbeckler.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}