Python Tutorial for Beginners 1: How to Install and Set Up Python 3 on Mac and Windows

4.2M views
May 17, 2017
by
Corey Schafer
YouTube video player
Python Tutorial for Beginners 1: How to Install and Set Up Python 3 on Mac and Windows

TL;DR

Install Python 3.6 from python.org, run the installer, and verify the installation from Terminal or Command Prompt. Mac users can run Python with python3 or map python to it through an alias, while Windows users should select “Add Python 3.6 to PATH.” Read on for exact installation, verification, IDLE, and first-script steps.

Transcript

hey there how's it going everybody in this series of videos we'll be going over the basics of Python Programming now I get a lot of messages from people who say that they enjoy my python videos but that they're either just getting started out in programming or coming from another language and would like a beginner's overview of python so that they ... Read More

Key Insights

  • Python 3 is the version beginners should install, as almost everyone is moving over to Python 3 and you should only use Python 2 if you have a really good reason to do otherwise.
  • Mac comes with Python pre-installed, but the default is usually Python 2.7, which you can confirm by opening the terminal and typing 'python --version'.
  • Installing Python 3 on Mac uses the 'python3' command by default, because the 'python' command still points to the pre-installed Python 2.7 version.
  • Creating an alias by adding 'alias python=python3' to the .bash_profile file lets the 'python' command run Python 3, with no space around the equals sign.
  • On Windows, checking the 'Add Python 3.6 to PATH' option during installation lets the python command work in Command Prompt without manually editing advanced system settings.
  • The interactive prompt, opened by typing 'python' in the terminal, lets you write one line of Python at a time, such as 'print' statements or setting variables like x = 10.
  • IDLE is a plain text editor that comes bundled with Python; on Mac it is in the applications folder and on Windows it is in the Python 36 folder from the start menu.
  • You exit the interactive prompt by typing 'exit()' with parentheses, and you create a runnable multi-line script by opening IDLE and choosing File then New File.

Install to Summarize YouTube Videos and Get Transcripts

Explore YouTube Video Summarizer or Get YouTube Transcript Extractor

Questions & Answers

Q: How do I install Python 3 on a Mac?

Go to python.org, open Downloads, and choose the detected Mac download for Python 3.6. Open the downloaded PKG file, follow the standard installation steps, and enter your password if requested. The installation creates a Python 36 directory in Applications.

Q: How do I check whether Python is installed on my Mac?

Open Terminal and run python --version. A Mac will usually report the pre-installed Python 2.7; after installing Python 3.6, run python3 --version to verify the new installation.

Q: Why does python still show Python 2.7 after installing Python 3 on Mac?

The Mac installation assigns Python 3 to the python3 command, while python continues to point to the pre-installed Python 2.7. Use python3 for your scripts, or create an alias if you want python to invoke Python 3.

Q: How do I make the python command run Python 3 on Mac?

Open ~/.bash_profile in Nano and add alias python=python3, with no spaces around the equals sign. Save with Control-X, then Y, then Enter, and reopen Terminal. Running python --version should then show Python 3.6.

Q: How do I install Python 3 on Windows?

Go to python.org, open Downloads, and select Python 3.6 for Windows. Run the installer and check “Add Python 3.6 to PATH” before completing setup. Reopen Command Prompt and run python --version to confirm Python 3.6 is available.

Q: What does adding Python to PATH do on Windows?

Adding Python 3.6 to PATH lets the python command work inside Command Prompt. Selecting the installer option avoids manually changing the path through advanced system settings.

Q: How do I create and run my first Python script with IDLE?

Open IDLE, choose File and then New File, enter print("hello world"), and save the file as intro.py. In Terminal or Command Prompt, run python followed by the file’s path; if it is on the Desktop, the demonstrated path is Desktop/intro.py.

Q: What is Python’s interactive prompt, and how do I exit it?

Typing python in Terminal or Command Prompt opens an interactive prompt where you can execute one line at a time. You can test a print statement or assign a value such as x = 10. Exit by entering exit() with the parentheses.

Summary & Key Takeaways

  • This beginner Python series covers the fundamentals: installing and running Python, working with data types, conditionals, loops and iterations, creating functions, importing modules, and using the standard library. The goal is a firm understanding of Python basics so viewers can better grasp more advanced topics later.

  • On Mac, Python usually comes pre-installed as Python 2.7. To install Python 3, go to python.org, download the auto-detected Python 3.6 PKG file, and run the standard installation, which places a Python 36 directory in the applications folder alongside any older versions.

  • Because the python command still points to Python 2.7 after install, you use python3 instead, or create an alias in .bash_profile. On Windows, download from python.org and check 'Add Python to PATH' during setup so the python command works in Command Prompt.


Read in Other Languages (beta)

Share This Summary 📚

Explore More Summaries from Corey Schafer 📚