Programming For Marketers: How To Install PythonAdrian Palacios
Note: This blog post is the second in a series written by our Sr. Web Analyst, Adrian Palacios, and is designed to provide marketers the information and instruction required for installing the programming language Python. In case you missed it, Adrian’s first post explains why marketers should consider doing so in the first place.
How do you start learning Python? The first thing you have to do is install it. Yes, just like you might install Adobe Photoshop, you need to get Python onto your computer. There is a chance that there is a very basic version of Python on your computer right now, but if that basic version is there it will feel like you are stuck using TextEdit or Notepad compared to installing and using Microsoft Word. In subsequent posts there are other “add-ons” we’ll also want to take advantage of, so overall it’s a good idea to do a fresh installation.
I highly recommend using Anaconda from a company called Continuum.io when you install. They make it easy to install and manage extensions of Python, as well as many other things (if any “real” programmer asks you in a condescending tone “Why aren’t you using PIP?” tell them it’s because you have a day job).
First, open your browser and go to Continuum’s Anaconda download page:
The steps may be a little different if you are on a Windows device, but overall, it’s the same process: download the right package and install. Next, scroll down and select the click the tab of operating system you are currently using; pick a version to download (the “graphical” or “bit” installer will be easiest to work with).
- download the right package and install
- scroll down and select the click the tab of operating system you are currently using
- pick a version to download (the “graphical” or “bit” installer will be easiest to work with)
Now look in your downloads folder and then double-click on the .pkg file:
After clicking on the .pkg file, some instructions should pop up:
Be aware that this program will take quite a bit of space on your computer!
It may take 5 to 10 minutes to finish running all the scripts necessary. Afterwards you should see this screen:
Ok–so now what? With this version of Anaconda there’s no icon like you might expect with, say, a program like Slack. Instead, we will “run” our program through Terminal. If you’ve never used Terminal before, you can find it under your applications. Double-click on the icon once you find it:
This is Terminal. It’s so bare and utilitarian that, like any uncharted territory, it can feel scary. But, where’s the fun in living on the safe side of life?
Using Terminal is a big hurdle in learning how to program: the familiarity and ease of use with pointing your mouse at something and clicking is gone. Instead, you have to type out commands that tell the computer what to do. However, once you figure out what commands to type into Terminal and the sequence in which each command should be run, you gain a lot of power. How so? Think of that dreaded report that requires what feels like a million, repetitive clicks and scrolls to finish.
Once you’ve crafted a recipe of commands for the computer to follow, the computer can do all that boring stuff for you, and it can do it much faster than you could ever click. Let’s practice now: with Terminal open, type in ls and hit the Enter/Return key; ls is a “list” command and will list all the files in your current directory:
While Terminal may feel completely foreign at first, notice that the words are familiar: Music, Documents, Downloads, etc. I can’t emphasize enough that Terminal is (mostly) a text representation of the folders and icons you are used to clicking and navigating through. The biggest difference is that with Terminal (and other similar Unix shells) you can run actual commands…you can tell your computer what to do!
One side note: if you happen to mention you used Terminal for the first time to a developer, they might think it’s really funny to tell you something along the lines of “Try the rm -rf command, it’s really useful.” Don’t do it. Basically, it deletes stuff. If anyone tries to play this prank on you, turn off your computer and tell them you ran the command but now your screen is blank and your computer won’t turn on. The look on their face should be priceless.
If you read through all the text you might notice something new…anaconda. That’s a good sign! Let’s type in another command: which python. If you see a string of text that ends with anaconda/bin/python, that’s also a good sign.
Let’s do a final test: type in ipython and hit Enter/Return. If anything happens like what you see below, then congratulations, you have installed Anaconda and can now run IPython–an interactive version of Python (unfortunately you need a fair amount of experience in programming Python to fully appreciate why this version feels so “interactive”).
What could go wrong?
Installing a souped-up version of Python can be one of the most difficult parts of getting started with programming. You may find out that your I.T. department has your computer locked down tight and you won’t have the right permissions to install the Anaconda platform. You might experience bizarre errors that even the most seasoned software engineer will find puzzling.
There are many things that can go wrong, but the good thing is that the smart folks at Continuum have tried to think of all those strange scenarios and the Anaconda platform works well in most cases. If it doesn’t, try looking through their support document on installation. If that doesn’t work, then Google whatever error you are getting (actually copy and paste it into Google) and follow any directions you might find.
If you’re still having issues, then find a programmer that would be willing to help. Before you actually talk to that person, it’s a good idea to read this article first about how to ask questions. If you’ve Googled, phoned a friend, and done everything else you can think of but still can’t get the Anaconda platform installed, there is a Plan B: repl.it is an awesome service that allows you to use Python directly in your browser with no setup necessary (although it may be a good idea to create an account so you can save your work). Unfortunately, this service will not allow you to do everything that’s planned in this series of posts, but it’s enough to get you started.
If you were able to get an IPython session started, then while we’re here let’s type in our first Python command: print(). It’s customary to print a “Hello World” message, so let’s do that now. One key lesson in programming is that every character you type matters. If you are a grammar stickler, today is your lucky day. If you aren’t, you will soon learn how to fastidiously proofread your code.
The print command takes what’s called a string. A string is typically text enclosed in quotes. Type out the command as show below, then hit the Enter/Return key. You should see the computer echo back your message:
Congratulations! You’ve just run your first Python command. Take a moment to celebrate 🙂
Additional Tutorials and takeaways
If you want a video version of how to install Anaconda on your Mac, I found this tutorial helpful. The first 5 minutes run through how to install, whereas the rest of the video is a more technical (but useful) introduction to the Anaconda Platform in general.
The process for installing the Anaconda platform on Windows is very similar. Here is a great YouTube video demonstrating how to install. Rather than opening Jupyter Notebook as shown in this video, I suggest trying Anaconda Prompt to run iPython and follow the example above.
In my next post, I’m covering data types and how they governs what you can and can not accomplish with Python. And don’t hesitate to reach out to me on Twitter if you have questions.