Edit: You can find the slides of the talk here.
Hey there! The aim of this post is to make sure that everyone is on the same page when we start with our upcoming hackeve. I'm going to go ahead and assume close to zero working knowledge and would in general be throwing around descriptions and explanations here and there. Let's walk through the basics of setting up the environment on which we'd be working.
There is just one thing that I assume that you already have installed, and that's a text editor. I prefer sublime text, but please don't get caught up in the wars between fanboys of notepad++, sublime text, emacs or vim. Remember, you'll see a lot of fights, but that's the only things that we as programmers love to waste time on. So pick any editor, and let's get started.
Baby steps - Installing Python
For those who are running any *nix system, take my hug and jump to the next section. For the rest of us, let's start by installing Python on our system. I'd suggest downloading from the official python site. We'll be using the python 2.7.* version. Let's allow the wizard to install python.
Cool, let's test this right now. I installed Python in the D drive. So let's open up the command prompt, navigate to the location and give it a whirl.
Yup. it works. Awesome :D
But come on! We do not want to always go to where we installed python, just to start it up, right? So we need a way to tell the prompt where to search for the corresponding program of the keywords I enter. So, if I type
python somewhere else, maybe in the
C:\ drive. The cmd/shell should still be intelligent enough to start
D:\Python\python.exe(in my case). This is exactly what the PATH is.
PATH is a list of directories which the shell searches whenever you type the name of a program. You need to add the python directory in the
For Windows: open up powershell, and type
set PATH=%PATH%;D:\Python. Remember to write the
%PATH%. Otherwise instead of appending to the
PATHvariable, you'll be overwriting it. shudder. Now restart your shell for the changes to take place.
People running *nix might not need to set the path right now, because python is included and added in the path by default. But just for the sake of completeness, here's how you add directories to your
And now you can be anywhere, typing
pythonstarts up the python interactive console.
Installing extra stuff
We'll need to install another extremely useful package,
pip. This package makes installing other python packages a breeze. Let's install it.
- If you've downloaded Python from the official site, you should have already gotten pip. Specifically, it should be in
Python/Scripts. So you could add this folder to your
PATHvariable, and you're set.
- Otherwise, download this file get-pip.py. And run
python get-pip.py. It'll install pip for you. While it's installing, try and open up the file in a text editor. You'll see a big string. This is actually the
pippackage itself. Since you would have needed a package installer to install a package installer, this was a simple and clever way to package this package for distribution. Zoinks.
- If you run into any trouble, ping us.
Now that you've installed pip, check it.
Let's get started. Please >:(
Sure, just a final step. I'm going to force you to install
virtualenv first. You might think that this is useless, but trust me. Use virtual environments. Please.
Alright, easy installation\upgrade process here. For windows, you need to open up a shell with administrator acces, and in *nix, run the command as superuser. Just do
pip install virtualenv --upgrade. That's it.
See? Even for us guys who prefer to work on windows, some tools are easier to install via a cli tool like pip, rather than wizards.
Now jump out of being the superuser/kill the cmd with administrator access. It's dangerous.
Let's go to wherever we're going to work. In my case,
D:\project\hackeve\ and create a virtual environment there.
Now we need to activate the environment. *nix guys, do
source myenv/bin/activate. Windows people, use
Cool. Do you know what you just did? You just saved yourself a lot of headache by giving this little project of yours its own personal space to install packages in. Let's suppose this little project uses a python package to use google-maps and you've written the code using that package. Now you start working on another project which also uses this same package, and you find that an upgrade is available. So you upgrade the package before starting your new project, unknowingly breaking this little pet project of yours completely. Sad, right? Well that's what virtual environments prevent from happening. Each of your projects have their own environment to work in and you can easily have multiple versions of the same package installed on your system at the same time because of this.
Enough already! :(
Alright alright.. In this coming hackeve we'll be learning about flask. So for the final step, let's install it.
Can you guess what should we do to install it?
pip install flask. Remember to run this after you activate your virtual environment, otherwise the whole point is moot.
Now create a new file
well_begun.py in your folder with the following contents.
from flask import Flask app = Flask(__name__) @app.route("/") def handle(): return "Doesn't matter if the work's incomplete." if __name__ == "__main__": app.run()
If you run
python well_begun.py and point your browser to
http://localhost:5000, and you see
Doesn't matter if the work's incomplete.
written, congrats ! You're set up for the hackeve.
Oh, and also.
You'll need to install
git. It's extremely difficult to explain in a blog post what
git is and why it is needed. It's too much info to digest right now, and also I might not be the best teacher for it. So, you'll have to delicately handle this giant until we come up with another hackeve to explain
git sometime later. However you can't skip this step, since we'll be using
git for running this hackeve.
For now, *nix users, do
sudo apt-get install git
And windows users, install git from the setup files given here.
What you'll be learning.
In this hackeve, you'll learn about the toned down basics of MVC frameworks. You'll realise how easy it is to create simple, basic and clean apps without writing too much code.
Initially, we'll be creating a simple counter which counts how many times you've pressed a button. After that, we'll make an authentication system and make sure that only the admin can see the counter.
Hope to see you there.