Sample Video Frame

Created by Zed A. Shaw Updated 2024-12-10 18:57:40

0: Gearing Up

This exercise has no code. It is simply the exercise you complete to get your computer to run Python. You should follow these instructions as exactly as possible. If you have problems following the written instructions, then watch the included videos for your platform.

General Instructions

Your general task is to get a "programming environment" with tools you can use to write code. Nearly every programmer has their own specialized environment, but at first you'll want something simple that can get you through this course. After the course you'll know enough about programming to then waste the rest of your life trying every tool you can imagine. It's a lot of fun.

What you'll need is the following, but don't install it yet. This is just a preview of what you'll install in a minute:

  1. Jupyter which will be used in the first part of the book to get you started easily. Jupyter is a programming and data analysis environment that uses many languages, but we'll use Python.
  2. Python. The version of Python you install mostly doesn’t matter so long as it’s newer than version 3.10. Versions of Python (and other software) use numbers to indicate their age, and the position of the numbers determines how much changed between versions. The general rule is the first number means “major change,” the second number means “compatible changes,” and a third number means only bug or security fixes. That means if you have version 3.8 and version 3.10, then they should be compatible. If you have versions 3.10.1 and 3.10.2, then there are only minor fixes.
  3. A basic programmer's editor. Programmers use very complicated text editors, but you should start with something simple that still works as a programmer's editor.
  4. A Terminal emulator. This is a text based command interface to your computer. If you've ever seen a movie with hacking and programming in it you've seen people furiously typing green text into a black screen so they can take down an entire alien race with their "unix exe 32 pipe attack". At first you won't need this but later you'll "graduate" to using the Terminal as it's incredibly powerful and not too hard to learn.

You should have most of the other things you'll need on your computer already, so let's install each of these requirements for your Operating System (OS).

Minimalist Start

The instructions in this exercise are designed to install most of the things you need for the rest of the course, but if you want to get going quickly with the least amount of work then install:

  1. Anaconda to get your python.

  2. Jupyter to write and run some code. This comes with Anaconda so you don't need to install it.

    • On Windows the best way to run Jupyter is to hit the windows key and type anaconda prompt. This will start a Terminal with Anaconda. Inside Anaconda Prompt type jupyter-lab. Later you'll do a better install method that makes this easier.
    • On Linux it should be the same command in your Terminal.
    • On OSX you can either type that command in the Terminal or start the app like normal.

This will give you enough to get started, but eventually you'll hit exercises that need the Terminal and Python from the "command line." Come back to this exercise when reach that point in the course.

Windows

Installation on Windows is so difficult that I've created a special automated install script for you. The install uses two PowerShell scripts to install all the software you need, and is easy to use. First, hit your Windows key to open the Start Menu, then type "powershell" to open a PowerShell instance (not PowerShell ISE). Once that's opened enter these two commands:

irm https://learncodethehardway.com/setup/base.ps1 -outfile base.ps1
powershell -executionpolicy bypass .\base.ps1

Be sure you stay at your computer while it runs. You'll be asked to enter your Administrator password for various installers, and some of them time out if you're don't do it quickly enough.

You should now close this PowerShell window and open a new one. In the new PowerShell window you repeat the process for python.ps1:

irm https://learncodethehardway.com/setup/python.ps1 -outfile python.ps1
powershell -executionpolicy bypass .\python.ps1

This script will install Official Python and Anaconda, because sometimes it doesn't work without this for...reasons. When it is ready to install Anaconda it will give you an important message to read about forcing Anaconda to add Python to the PATH. Be sure you read it and do as it says, no matter what Anaconda tells you, add it to the PATH!

When Anaconda is done installing you want to close that PowerShell and open one more PowerShell window. In this new window type:

conda init powershell

If you are told that conda doesn't exist then you either didn't start a new PowerShell window, or you didn't tell Anaconda to add itself to the PATH. Uninstall Anaconda and rerun powershell -executionpolicy bypass .\python.ps1, but this time check the box that says add it to the PATH. Then run conda init powershell one more time.

After that, close PowerShell for the final time, hit your Windows key, and type "terminal" into your start menu. You should see a new application Terminal. Run this and you should be able to do the test at the end of this exercise.

NOTE There are other scripts that install other languages, so if you need installs for Rust, Zig, Crystal, C, C++, and many others check out the git project page for more. All of these installers use winget and choco to do the installs, so you can use those tools directly instead of my scripts if you want.

If you install all of those things then you should be ready to go. However, here are few alternative suggestions for certain people:

  1. Visual Studio Code is a more powerful programmers editor, but you should only use this when you're better at programming. You can think of Geany as a really nice bicycle you can learn to ride on, and Visual Studio Code as a Harley-Davidson Road Glide Special with extended forks and a side car seat.

macOS

The setup for macOS is almost the same as Windows, except you don't need a separate Terminal program as macOS already has one:

  1. Anaconda This is the easiest way to get a working Python install. When you install it make sure to add it to your PATH, even if it warns you that this will cause problems.
  2. Geany is a great little text editor for programming. It supports almost everything you need, is small, runs on low power computers, and runs on nearly every OS. I highly recommend this for when you're starting out.
  3. Terminal is already installed on your Mac, but you will want to add it to your Dock. Hit command-space and type "terminal" to start it. Once it's running, right click on the icon in your Dock and select the option to keep it in your Dock.
  4. Jupyter will be your primary programming environment for a while. This comes with Anaconda so you don't need to install it. You can think of Jupyter as an editor and terminal all in one program. There's even psychopaths who do all of their work only in Jupyter. It's a great tool for interactively working on ideas and doing data analysis.

These are nice to have software for more advanced people:

  1. Visual Studio Code as I mentioned in the Windows instructions, Visual Studio Code (VSC) is powerful, but you really do not need it early on.
  2. iTerm2 is a really nice Terminal program for macOS.
  3. The official Python Installer but I really recommend Anaconda instead as it'll work better with your macOS computer.

Linux

If you are a beginner DO NOT INSTALL LINUX. I do not care what any other programmer tells you, Linux is incredibly difficult to use if you are not a major expert at computers. I've been using Linux since the day it came out, originally installing it on a 80386 Compaq computer using a giant box of 70 3.5" floppy disks shipped to me from Slackware, and I can't even get Linux to work right on my laptop computer. If I can't make Linux work reliably then there is no hope for you, and anyone telling you to install Linux should be completely ignored. That person is only trying to get you to install Linux to increase the membership of their "tribe" and actually doesn't care about your learning objectives.

The Linux required software is almost exactly the same, but you're Linux distro will have its own way to install and manage software.

  1. Anaconda This is the easiest way to get a working Python install. When you install it make sure to add it to your PATH, even if it warns you that this will cause problems.
  2. Jupyter will be your primary programming environment for a while. You can think of Jupyter as an editor and terminal all in one program. There's even psychopaths who do all of their work only in Jupyter. It's a great tool for interactively working on ideas and doing data analysis. Jupyter comes with Anaconda so you don't need to install Jupyter separately.
  3. Geany is a great little text editor for programming. It supports almost everything you need, is small, runs on low power computers, and runs on nearly every OS. I highly recommend this for when you're starting out.
  4. Whatever terminal program your version of Linux already has will be fine.

As with the Windows and macOS there's a few optional things you could install:

  1. Visual Studio Code you're a Linux user now so this editor isn't for you. It's by Micro$oft and no real Linux user would dare touch anything by the authors of the Halloween Memo. If you're smart enough to not care then VSC is a good professional development environment, but stick to Geany until you're more capable.
  2. Vim I don't normally recommend Vim to beginners, as it's a powerful but difficult editor to learn, but you're a Linux user now. That means you love yak shaving and obsessing over tools so go for it.
  3. Emacs is an even hairier yak you can shave. Get out those clippers because you'll spend the next 10 years tweaking your Emacs Lisp configurations instead of learning to code.

All jokes aside, just stick to Geany unless you are already good with an editor you like. If you're a beginner hell bent on running Linux then good luck. I'm sure it won't get in the way of you learning to code. Nope, it's totally easy to learn 5-10 things at once.

Testing Your Setup

NOTE Before we continue, I'm going to use the word Terminal whenever I mean "start PowerShell" if you're on Windows, or "start Terminal" when you're on macOS/OSX. Just remember, every time I say "start your Terminal" it's just a placeholder for PowerShell on Windows or Terminal on OSX.

Once you have everything installed go through these steps to confirm that everything is working:

  1. Start your Terminal (PowerShell on Windows, Terminal on OSX, etc.) and type this command exactly, spaces and all: mkdir lpythw.
  2. Once that works you have a directory lpythw that you can place your work.
  3. Go into that directory with the command cd lpythw. This command "moves" your terminal into that directory so your work is saved there.
  4. A "directory" is also called a "folder" on Windows and macOS. You can make the connection between the "directory" in your terminal and the "folder" you normally see by typing start . on Windows or open . on macOS. This opens the current directory into a graphical folder window you're used to normally seeing. If you're ever lost, type that.
  5. The start command (open on macOS) works like double-clicking that thing with your mouse. If you are in the terminal and want to "open" something, just use this command. Let's say there's a text file named test.txt and you want to open it in your editor. Type start test.txt on Windows or open test.txt on macOS.
  6. Now that you can open your Terminal and open things while in your Terminal, you'll want to start your editor. This is Geany if you've been following instructions. Start it and create a file named test.txt and save it in the lpythw directory you made. If you can't find it remember you can open it from the Terminal with start (open on macOS) and then use that folder window to find it.
  7. Once you've saved the file in the lpythw directory you should be able to type ls test.txt in your Terminal to see that it's there. If you get an error then either you're not in the lpythw directory and need to type cd ~/lpythw or you saved it in the wrong place. Try again until you can do this.
  8. Finally, in the Terminal type jupyter-lab to start up Jupyter and make sure it works. It should open your web browser and then you'll see the Jupyter app inside your browser. It's kind of like a little website on your personal computer.

Think of these tasks as a kind of puzzle to solve. If you get stuck you should watch the video for your Operating System (OS) where I show you how to do everything. I think the best way to learn this is to first attempt it yourself, then when you get stuck watch the video to see how I did it.

Learning the Command Line

You don't need to do this right now, but if you're struggling with the tasks above you might need to go through Exercise 38 if you use Windows, or Exercise 39 if you use macOS or Linux to learn the basics of the Terminal (also called the Command Line). You won't need these skills for a while but the command line is a very good introduction to controlling your computer with words. It will also help you with many other tasks in programming later, so learning it now can only help.

Next Steps

Once you have everything working you can continue with the rest of the course. If you ever run into trouble you can email me at help@learncodethehardway.com and I'll help you. When you email me for help take the time to describe your problem in as much detail as possible, and include screenshots.

Back to Module Next Lesson

Register for Learn Python the Hard Way, 5th Edition (2023-2024)

Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.