Boston Python Workshop/Friday handout/Windows: Difference between revisions

From OpenHatch wiki
Content added Content deleted
imported>Paulproteus
imported>Brittag
(removing spam)
 
(31 intermediate revisions by 6 users not shown)
Line 3: Line 3:
* You may need to login as Administrator, or give the Administrator password when installing some programs, depending on your Windows version and user settings.
* You may need to login as Administrator, or give the Administrator password when installing some programs, depending on your Windows version and user settings.
== Open a Command Prompt ==
== Open a Command Prompt ==
* Open a command prompt window, and keep it open along with your browser. Much of installing Python and using Django is typing commands and hitting '''<enter>'''. Your experience using Rails on Windows greatly depends on your making friends with the command prompt window.
* Open a command prompt window, and keep it open along with your browser. Much of installing Python and using Django is typing commands and hitting '''<enter>'''. Your experience using Python on Windows greatly depends on your making friends with the command prompt window.
* This is also called the command prompt, command window, command-line window, MS-DOS or DOS window.
* This is also called the command prompt, command window, command-line window, MS-DOS or DOS window.
http://www.wiki.devchix.com/index.php?title=Opening_a_command_prompt_window
http://www.wiki.devchix.com/index.php?title=Opening_a_command_prompt_window
Line 18: Line 18:
* Go to http://python.org/download/ and download the latest version of Python ''2.7'' (2.7.1 at the time of writing).
* Go to http://python.org/download/ and download the latest version of Python ''2.7'' (2.7.1 at the time of writing).


* Test your Python install in the command prompt using the "-v" version flag:
* Test your Python install in the command prompt:


\python27\python.exe -v
\python27\python.exe


You should see something like
You should see something like
Line 36: Line 36:


== Install Git for Windows ==
== Install Git for Windows ==
* Go to http://code.google.com/p/msysgit/ (aka GitBash)
* Go to [https://code.google.com/p/msysgit/downloads/list the downloads page for GitBash]
** Click on the top "Downloads" tab
** Download the top .exe file link with the Summary something like "Full installer for official Git 1.7.x.x"
** Download the top .exe file link with the Summary something like "Full installer for official Git 1.7.x.x"
* Run the install.
* Run the install.

'''Note''': You can't just click through the installer. You have to answer some questions!

* In the "Select Components" dialog, make sure the checkboxes "Associate ... configuration files ..." and "Use a TrueType font ..." are checked.
* In the "Select Components" dialog, make sure the checkboxes "Associate ... configuration files ..." and "Use a TrueType font ..." are checked.


* ''Important'': In the "Adjusting your PATH environment" dialog, make sure "Run Git from the Windows Command Prompt" is selected.
* ''Important'': In the "Adjusting your PATH environment" dialog, make sure "Run Git from the Windows Command Prompt" is selected.
* In the "Configuring the line ending conversions" dialog, make sure "Checkout Windows-style, commit Unix-style line endings" is selected.
* In the "Configuring the line ending conversions" dialog, make sure "Checkout Windows-style, commit Unix-style line endings" is selected.
* To run git, open Programs > Git > Git Bash
* To run git, open Programs > Git > '''Git Bash'''
* Then to test the Git install and see Git commands, in the command prompt type:
* Then to test the Git install and see Git commands, type this into the '''Git Bash''' prompt:
<pre>
<pre>
git
git
</pre>
</pre>

'''Note''': From here forward, when we need a command prompt, we'll use the '''Git Bash''' prompt, because it is more featureful.


== Configure Git ==
== Configure Git ==
* Set up Git with your name and email to tag your code changes. In the command prompt type:
* Set up Git with your name and email to tag your code changes. In the command prompt type:
<pre> git config --global user.name <Your ActualName> </pre>
git config --global user.name "''Your ActualName''"
* Replace ''Your ActualName'' with your actual name.
and:
<pre> git config --global user.email <YourEmail@domain.com> </pre>



* Tip: '''Colors'''
git config --global user.email YourEmail@domain.com
<br/>
* Replace ''YourEmail@domain.com'' with your email address.

Test it:

git config --global user.name
git config --global user.email


=== Tip: Colors ===
To have colored output, in the command prompt type each line followed by '''<enter>''':
To have colored output, in the command prompt type each line followed by '''<enter>''':

<pre>
git config --global color.diff auto
git config --global color.diff auto
git config --global color.status auto
git config --global color.status auto
git config --global color.branch auto
git config --global color.branch auto
</pre>


== Install SQLite Manager ==
== Install SQLite Manager ==
Line 85: Line 96:


== Create an ssh public key ==
== Create an ssh public key ==
You'll need one of these to create your Heroku account in the next section.
You'll need one of these to work with Github.

* Open up a new GitBash window.
* Get into a GitBash window.
* <code>ssh-keygen -C &quot;''Your Actual Email''&quot; -t rsa</code> (email should match git config setting)
* <code>ssh-keygen -C ''Your Actual Email'' -t rsa</code> (email should match git config setting)
* Hit enter to accept default location for ssh key.
* Hit enter to accept default location for ssh key.
* Hit enter to accept blank passphrase (if computer is shared with other people, as in a work laptop, you should create a passphrase). Hit enter again to accept blank passphrase (or enter passphrase again).
* Hit enter to accept blank passphrase (if computer is shared with other people, as in a work laptop, you should create a passphrase). Hit enter again to accept blank passphrase (or enter passphrase again).

* [[Output of ssh-keygen command]]
* Your brand-new public key is now stored at <code>~/.ssh/id_rsa.pub</code>.
* Your brand-new public key is now stored at <code>.ssh/id_rsa.pub</code> inside your Windows profile.

'''Note''': The ''ssh-keygen'' command will give you a bunch of output. You don't have to record that output anywhere.


== Django ==
== Django ==


* Open a new GitBash window.
* Open a new GitBash window. Type each of these, and press enter at the end of the line.


curl -L http://www.djangoproject.com/download/1.2.5/tarball/ -o Django-1.2.5.tar.gz
curl -L http://www.djangoproject.com/download/1.2.5/tarball/ -o Django-1.2.5.tar.gz
tar zxvf Django-1.2.5.tar.gz
tar zxvf Django-1.2.5.tar.gz
cd Django-1.2.5
cd Django-1.2.5
python setup.py install
/c/python27/python setup.py install
cd ..


== Verify you can create a new Django app ==
== Verify you can create a new Django app ==
Line 115: Line 130:
* In your browser, go to http://localhost:8000/
* In your browser, go to http://localhost:8000/
* Back in the Terminal window where you ran <code>manage.py runserver</code>, type control-c to kill the server.
* Back in the Terminal window where you ran <code>manage.py runserver</code>, type control-c to kill the server.

== Cleanup ==
Ok, there is one more step. You won't be using the test project in the workshop; we just created it to make sure everything was working. '''You should delete it now to reduce confusion during the workshop.''' Don't worry about losing information; it just has the test project in it.

* Exit the GitBash terminal
* Drag the myproject folder (inside django_projects) to the Recycle Bin. Leave django_projects on the desktop.


== Congratulations! ==
== Congratulations! ==
Line 120: Line 141:
You have everything you need to write a Django web application in Python.
You have everything you need to write a Django web application in Python.


...on '''your''' machine.
== Cleanup ==

Ok, there is one more step. You won't be using the test application in the workshop; we just created it to make sure everything was working. '''You should delete it now to reduce confusion during the workshop.''' Don't worry about losing information - you'll repeat all the steps tomorrow, but more slowly so you can better understand what's going on under the hood.
The next set of directions help you use alwaysdata.com and its free-of-cost hosting.

== Install PuTTY ==

PuTTY is a program we'll use to log in to the server where your Django code runs.

* Go to the [http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html PuTTY download page]
* Choose the '''putty-0.60-installer.exe''' file.
* Run the installer, and now you will find PuTTY in
** '''Start'''->'''Programs'''->'''PuTTY'''


'''Now go back to the [https://openhatch.org/wiki/Setting_up_the_web_app#Section_3:_Configuring_your_accounts_on_the_web web app install instructions]'''
* Drag the test_app folder (inside rails) to the trash. Leave rails on the desktop.
* Delete the app from Heroku. Go to https://heroku.com/myapps and then click on your app name. Scroll to the bottom of the page and click Destroy App.

Latest revision as of 07:57, 18 August 2013

About Django on Windows

  • These instructions should work for all versions of Windows from XP on to Windows 7.
  • You may need to login as Administrator, or give the Administrator password when installing some programs, depending on your Windows version and user settings.

Open a Command Prompt

  • Open a command prompt window, and keep it open along with your browser. Much of installing Python and using Django is typing commands and hitting <enter>. Your experience using Python on Windows greatly depends on your making friends with the command prompt window.
  • This is also called the command prompt, command window, command-line window, MS-DOS or DOS window.

http://www.wiki.devchix.com/index.php?title=Opening_a_command_prompt_window

  • Try these recommendations:

http://www.wiki.devchix.com/index.php?title=Recommended_setup_for_command-line_windows

  • Tip: clear screen
    If you ever want to clear the "output history" to get a clear screen, type:
cls
  • Tip: command history
    The command prompt window stores a "command history." To view and re-run previous commands, use the <up arrow> and <down arrow> keys. You can also edit a previous command and run it--this is handy for long commands, or fixing mistakes.
  • Tip: copy and paste
    In the instructions below, where it says: "In the command prompt type:", you can, much more easily, copy the command from this page, and right click in the menu bar or command prompt window, then click on "Paste", then hit the <enter> key.

Install Python

  • Test your Python install in the command prompt:
\python27\python.exe

You should see something like

Python 2.7.1 (r271:86832, ...) on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
  • Type
exit()

and press Enter, and you are back to the command prompt.

Install Git for Windows

  • Go to the downloads page for GitBash
    • Download the top .exe file link with the Summary something like "Full installer for official Git 1.7.x.x"
  • Run the install.

Note: You can't just click through the installer. You have to answer some questions!

  • In the "Select Components" dialog, make sure the checkboxes "Associate ... configuration files ..." and "Use a TrueType font ..." are checked.
  • Important: In the "Adjusting your PATH environment" dialog, make sure "Run Git from the Windows Command Prompt" is selected.
  • In the "Configuring the line ending conversions" dialog, make sure "Checkout Windows-style, commit Unix-style line endings" is selected.
  • To run git, open Programs > Git > Git Bash
  • Then to test the Git install and see Git commands, type this into the Git Bash prompt:
git

Note: From here forward, when we need a command prompt, we'll use the Git Bash prompt, because it is more featureful.

Configure Git

  • Set up Git with your name and email to tag your code changes. In the command prompt type:
git config --global user.name "Your ActualName"
  • Replace Your ActualName with your actual name.


git config --global user.email YourEmail@domain.com
  • Replace YourEmail@domain.com with your email address.

Test it:

git config --global user.name
git config --global user.email


Tip: Colors

To have colored output, in the command prompt type each line followed by <enter>:

git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto

Install SQLite Manager

  • If you already have Firefox installed, verify that it is version 3.5.0 or greater. (Help -> About Mozilla Firefox. The version number is right under the "Firefox" title.)
  • If you don't have Firefox installed, or it's an older version, install Firefox.
  • Once it's installed, open Firefox and go to Tools -> Add-ons. At the top of the add-ons window, click "Get Add-ons."
  • There will be search box directly underneath "Get Add-ons" that says "Search All Add-ons." Enter "SQLite" (without the quotes) in the box and hit enter.
  • SQLite Manager should be the top result. Click "Add to Firefox..." (If SQLite Manager isn't in the results, check the spelling - SQLite only has one L. Also, check that you have at least Firefox 3.5.)
  • Wait for the countdown, then click "Install Now."
  • In the Add-ons windows, click "Restart Firefox."
  • Once Firefox restarts, the Add-ons window should say "1 new add-on has been installed." Go to the Tools menu and verify that there is an option for SQLite Manager.


Install KomodoEdit

You need a text editor to do Python. If you already have a preferred text editor, such as vi, emacs, jedit, etc., you can skip this step. It must be a plain text editor and not something with styling like Microsoft Word.

When in doubt, use KomodoEdit.

Create an ssh public key

You'll need one of these to work with Github.

  • Get into a GitBash window.
  • ssh-keygen -C Your Actual Email -t rsa (email should match git config setting)
  • Hit enter to accept default location for ssh key.
  • Hit enter to accept blank passphrase (if computer is shared with other people, as in a work laptop, you should create a passphrase). Hit enter again to accept blank passphrase (or enter passphrase again).
  • Your brand-new public key is now stored at .ssh/id_rsa.pub inside your Windows profile.

Note: The ssh-keygen command will give you a bunch of output. You don't have to record that output anywhere.

Django

  • Open a new GitBash window. Type each of these, and press enter at the end of the line.
curl -L  http://www.djangoproject.com/download/1.2.5/tarball/  -o Django-1.2.5.tar.gz
tar zxvf Django-1.2.5.tar.gz
cd Django-1.2.5
/c/python27/python setup.py install
cd ..

Verify you can create a new Django app

  • Create a folder on the desktop called django_projects
  • Open a new GitBash window and type the following:
   cd Desktop/django_projects
   /c/python27/scripts/django-admin.py startproject myproject
  • Both commands should provide no output.
  • Once that's finished, type the following in the Terminal window:
   cd myproject
   /c/python27/python manage.py runserver
  • The first command should produce no output. The second command will put out a bunch of output, then just sit there until you cancel it (2 steps from now).
  • In your browser, go to http://localhost:8000/
  • Back in the Terminal window where you ran manage.py runserver, type control-c to kill the server.

Cleanup

Ok, there is one more step. You won't be using the test project in the workshop; we just created it to make sure everything was working. You should delete it now to reduce confusion during the workshop. Don't worry about losing information; it just has the test project in it.

  • Exit the GitBash terminal
  • Drag the myproject folder (inside django_projects) to the Recycle Bin. Leave django_projects on the desktop.

Congratulations!

You have everything you need to write a Django web application in Python.

...on your machine.

The next set of directions help you use alwaysdata.com and its free-of-cost hosting.

Install PuTTY

PuTTY is a program we'll use to log in to the server where your Django code runs.

  • Go to the PuTTY download page
  • Choose the putty-0.60-installer.exe file.
  • Run the installer, and now you will find PuTTY in
    • Start->Programs->PuTTY

Now go back to the web app install instructions