Installing Python

Mac vs. Windows vs. Linux
The installation instructions are a bit different depending on which operating system you're on. This course provides instructions for only Mac and Windows, you can skip to whatever page is appropriate for you. Again, while Linux OS is acceptable, please note that this course currently does not provide instructions for installing or using software on Linux.

Windows
Installing git bash
Before we install Python we need to get you a Unix-style shell--meaning it is compatible with the shell used on Mac and other Unix-like systems, which is what the majority of web servers run-on. Windows comes from a different lineage of operating systems than Mac, so it takes a little extra effort to get Windows compatible with the rest of the world. The most popular Unix-style shell for Windows is the one that comes with the Git Version Control software, it's called Git Bash
Here's a Checklist
Installing Python
Now that you have Git Bash set up, let's download Python
Here's a Checklist
Git bash configuration for python
Trouble running Python directly in git bash
Throughout this lesson, we will be running Python by entering python3 in the terminal (or command prompt) and then hitting enter. We will dive deeper into this topic in future lessons, but essentially when you run python3 in Git Bash you should see some info about the current Python version and the prompt should change to >>>, as demonstrated below.
(NOTE: The example below is a sample format; the actual output on your command prompt may vary.)
$ python
Python 3.11.7 (main, Dec 4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin Type "help", "copyright", "credits" or "license" for more information.
>>>

However, there is a common issue in Git Bash that you will likely run into. Instead of Python starting, Git Bash will simply display a blank line and sit there doing nothing, like this:

$ python

If this happens, you may need to exit Git Bash and restart.

This can be fixed, but we do want to acknowledge that it is a bit annoying--you'll need to follow along carefully with the instructions below to make sure your Git Bash is configured correctly for the remainder of these lessons.

Solution #1: Running Python with winpty
To avoid the problem, you can insert winpty at the beginning of the command. IN other words, during the rest of this lesson, whenever you are asked to enter this:
python
You can instead enter:
winpty python
As you can see, this works fine:
$ winpty python
Python 3.11.7 (main, Dec 4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin Type "help", "copyright", "credits" or "license" for more information.
>>>
When you see the >>> prompt like this, it means Python is currently running! While Python is running like this, you won’t be able to enter Git Bash commands. To exit Python, you can type in exit() and press enter–and this will return you to Git Bash.
Solution #2: Creating an alias
Typing winpty over and over does work, but it can be a nuisance, so we recommend that you create something called an alias. That looks like this:
alias python='winpty python'
If you run this line in Git Bash, then for the rest of the current session (meaning, until you restart Git Bash), you will then be able to enter simply python and Git Bash will know that you really mean winpty python.

$ alias python='winpty python'

$ python
Python 3.11.7 (main, Dec 4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin Type "help", "copyright", "credits" or "license" for more information.
>>>

Solution #3: Making a permanent alias
If you want to avoid creating the alias every time you restart Git Bash, you can make the change permanent by running the following line in Git Bash:
echo "alias python='winpty python.exe'" >> ~/.bashrc
You can copy and paste this line into Git Bash. If you then try to run Python immediately after, it may not work (see below).

$ echo "alias python='winpty python.exe'" >> ~/.bashrc

$ python

But if you restart Git Bash and then run python, it should work fine (without having to enter winpty before the python)
$ python
Python 3.11.7 (main, Dec 4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin Type "help", "copyright", "credits" or "license" for more information.
>>>
Once you have created this permanent alias, you should be all set and be able to run Python as shown throughout the rest of the course.

macOS
Installing Python
Let's download Python on macOS:
Last login: Sun Jun 9 15:25:00 on ttys000
username@Name-MacBook-Pro ~ % python
Python 3.11.7 (main, Dec 4 2021, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Next
Next

Installing VS Code