Friday, January 24, 2014

FLASK PYTHON TUTORIAL, WINDOWS 8.1, Virtualenv Python Flask on Windows 8.1 012414 

0. Download and install python2.7.6, python 3.3 may not work with this tutorial
add C:\Python27\; to Environment Variable Path

1. Go here to install easy_install for Windows

Copy and save this file in Documents as distribute_python.py

2. Go to cmd, cd to dir where distribute_python.py is located
run at prompt 
>python distribute_python.py
I saved it in Documents dir/folder

3. Go to Start/Control Panel/System/Advanced System Settings/Environment Variables and add to Path C:\Python27\Scripts\;

This is my Path now:
%INTEL_DEV_REDIST%redist\intel64\compiler;%INTEL_DEV_REDIST%redist\ia32\compiler;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\MATLAB\R2013a\runtime\win64;C:\Program Files\MATLAB\R2013a\bin;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Java\jdk1.7.0_51\bin\;C:\Python27\;C:\Python27\Scripts\;

4. At cmd prompt install pip
Users\Dell\Documents>easy_install pip


5. mkdir blog

6. copy make file and paste as virtualenv191.py in blog dir

7. run python virtualenv191.py flask at blog dir
users/dell/documents/blog> python virtualenv191.py flask
this makes a flask dir with virtualenv191 installed in it

8. Select all. copy and paste at the blog prompt, right click to paste at cmd prompt, it should begin auto installing
users/dell/documents/blog>
flask\Scripts\pip install flask==0.9
flask\Scripts\pip install flask-login
flask\Scripts\pip install flask-openid
flask\Scripts\pip install sqlalchemy==0.7.9
flask\Scripts\pip install flask-sqlalchemy==0.16
flask\Scripts\pip install sqlalchemy-migrate==0.7.2
flask\Scripts\pip install flask-whooshalchemy==0.54a
flask\Scripts\pip install flask-wtf==0.8.4
flask\Scripts\pip install pytz==2013b
flask\Scripts\pip install flask-babel==0.8
flask\Scripts\pip install flup
9. Install this separately since it has problems installing, it probably could be included in the #8 list above but the tutorial had it separate.
flask\Scripts\pip install --no-deps lamson chardet flask-mail==0.7.6

10. cd to blog dir, copy and paste at prompt, right click to paste at cmd prompt
users/dell/documents/blog>
mkdir app
mkdir app/static
mkdir app/templates
mkdir tmp
11. save in app dir as __init__.py, app/__init__.py
from flask import Flask

app = Flask(__name__)
from app import views
12. Save in app dir as views.py, app/views.py
from app import app

@app.route('/')
@app.route('/index')
def index():
    return "Bonjour, Bassets!"
12a. This file as views.py also works.

from app import app

@app.route('/')
@app.route('/index')
def index():
    return "Buongiorno, Principessa Bassets!"

13. Save in root or blog dir as run.py, blog/run.py
#!flask/bin/python
from app import app
app.run(debug = True)
14. At root dir/folder, execute run.py, the backslashes are needed in Windows, not forward slashes as for Linux, case insensitive in Windows, case sensitive in Linux.
This invokes the virtualenv version of python and not the system version of python to execute the script run.py.
users/dell/documents/blog>flask\scripts\python run.py
It works it gives this
*Restarting on reloader

He has this which is wrong
flask/Scripts/python run.py
It should be, this works
flask\Scripts\python run.py
15. View on web browser go to localhost:5000, no need to have WAMP installed or started since the installation will have a webserver, not sure if it is in the Python or virtualenv installation that has the webserver

16, It works

17. Ctrl C to break from webserver