Beginner's guide to Python on Mac: Set up, coding basics, training courses (2024)

Learning to code is hugely popular at the moment, and Python is a great coding language to learn. Luckily for us, the Mac is a great coding platform, and Python makes it easy to learn how to code on a Mac.

In this feature, we’re going to look at setting up Python in macOS, then learning to code on this platform. The learning curve is very manageable; Python may even be installed on your Mac already. (If not, don’t worry: we’ll cover installation too.)

We focus on Python here, but for a broad overview of Mac coding and the various languages you can choose from, read our complete guide to coding and programming on a Mac.

The benefits of Python

Python is a high-level programming language that was developed in 1991. Over the past few years, with the influx of coding into schools, it has ballooned in popularity, especially in England. Why is that? What benefits does it have over other languages?

Simplicity. One of the first benefits that Python has over other languages is how simple it is. The syntax is very easy to read. You won’t spend a lot of time having to memorise lines of syntax, which allows you to focus on the basic programming concepts, and it becomes a good starting point for learning other languages.

Power. Despite being simple, Python is very powerful. It is fully extensible with the various extensions that it has available. You can achieve almost anything with Python, from applications and games to machine learning.

The community. Python also has a huge community and masses of learning material is available. No matter what problem you’re having, there will be someone out there who can help you.

Low costs. Python is free and open source, which means you don’t have to pay a penny to start using it. There are hordes of other programmers out there continually trying to improve Python, and the various editors and compilers that are available for it.

It’s good for your career. Finally, Python is one of the most in-demand programming languages (alongside JavaScript and Java). This is a great starting point if you’re looking to get into a programming position.

Install Python

Python may be installed on your Mac already: you can test this out by opening Terminal and entering python –version.

If it’s not, you should make your way to the Python website 
and click the download button. Don’t be put off if the version number is different to the screenshot below – it may have been updated. The version at the time of writing is 3.7.0.

Beginner's guide to Python on Mac: Set up, coding basics, training courses (1)


Once you’ve clicked the download button, a .pkg file will begin to download.
 When it’s finished, navigate to the downloads folder and double-click on this file to open the installer. Follow the steps onscreen to complete the installation.

Beginner's guide to Python on Mac: Set up, coding basics, training courses (2)

Best Python text editors

By default, Python files (ending in .py) will open in TextEdit, and this won’t do. It has a nasty habit of a writing files in non-ASCII format, which messes things up. It also lacks any decent formatting options.

So you’ll need to install a great text editor. Fortunately, there are a few available.

The first text editor that you may come across in Python is IDLE. This can be found bundled with Python when you first install it, and you will find it located in the Applications folder.

Beginner's guide to Python on Mac: Set up, coding basics, training courses (3)

IDLE is an integrated development environment that allows you to both edit your code and see what the output will be after running it. It is the easiest editor, and the most recommended when you first get up and running. Once you’ve gained some experience you may want to move on to something more advanced.

PyCharm is possibly the most popular Python IDE out there at the moment, offering both a free and paid-for version: the latter has a wider range of features, but the freebie offers more than enough for the beginner. Features include access to plugins and web development support, as well as the usual editor offerings such as syntax highlighting.

Eclipse is an IDE that’s been around for quite a while now, offering support for a variety of different languages. To use it with Python, install Eclipse IDE for JavaScript and Web Developers, based on Eclipse Neon 4.6, then add the PyDev plugin. PyDev and Eclipse work together to create an excellent IDE for Python which is updated regularly by the hardworking Python community.

TextWrangler is a free download from the App Store. It’s a lightweight version of BBEdit but has all the functionality you need. One of the best choices for starting out.

Geddit is a popular choice amongst Linux fans, so it’s good for programmers to learn. Not as slick as other options, but very functional.

Sublime Text is a personal favourite. You can download and use it for free, although it’ll occasionally nag you into paying for it. A slick interface that’s easy on the eyes with great formatting control.

First steps and the basics

Now you have enough information about Python and what to use, it’s time to start some actual coding. With Python the majority of the commands are based around contextual words in the English language. So whereas C# would require you to type in Console.WriteLine in order to print some writing to the screen, Python just requires the simple command print. We’re going to look at 3 simple tasks that form part of the building blocks of coding. Creating an output, making a calculation, and using an if statement.

For our first task we’re going to use IDLE. It is easy to use and comes packaged with Python when you install it, so it makes sense to start out using it. Open up IDLE, by going to your Applications folder and double clicking it.

Once we have IDLE open it will open up a window called the shell. This is where all of our outputs will appear, but we aren’t going to do our coding in there. To do that we need to create a new file. We can do this by clicking File > New File in the top menu. This will open up a new code editor.

Beginner's guide to Python on Mac: Set up, coding basics, training courses (4)

Now that you have two windows open, feel free to lay them out whichever way you feel most comfortable with. We have set ours out side by side as shown below.

Beginner's guide to Python on Mac: Set up, coding basics, training courses (5)

Once you’ve set up your layout, click on the code editor window that opened up, and then click on File > Save As in the menu. Then save it as helloworld.py. As is customary in programming, the first program that you write will output “Hello World” to the screen.

We’re going to go to our code editor window and type in instructions that we would like our shell to carry out. The command we are going to use is the print command. This command looks like this.

print( )

Inside the brackets is where you put what you would like to be printed. So we’re going to use print to create an output to the shell, like this:

print(“Hello World”)

Once you have typed that, click File > Save from the menu to save the updated program, and then click Run > Run Module from the menu. Your output will appear then appear in the shell window. It should look something like this.

Beginner's guide to Python on Mac: Set up, coding basics, training courses (6)

It is important to put the speech marks around any words that you would like to be printed to the shell, the reasons why are for another time, but for now just remember that words need speech marks around them just like talking in a book would. Have a practice printing different phrases to the screen to get used to it.

Our second task is to use Python to do a calculation for us. So we’re going to open up the shell again and open up a new file, just like we did before. This time we’re going to name our file Calculation.py.

This time instead of printing words, we’re going to print a calculation. We are going to add 9 and 8 together, so we need to type into our new file our new print command, which looks like this.

print(9+8)

Once we have done this we need to save and then run the program by clicking Run > Run Module. You will notice now that the shell that it prints the answer, as you can see below.

Beginner's guide to Python on Mac: Set up, coding basics, training courses (7)

Try different calculations to get used to using the skill, remember that numbers don’t need the speech marks around them. If you are not already familiar with programming, you can use * to multiple and / to divide.

Finally, we will create one more basic program that will use something called an if statement. This allows us to do something if it meets a certain condition. Let’s open up a new file again, and write out the following syntax:

myNumber = 100if myNumber > 50: print(“That is a high number”)else: print(“That is a low number”)

Here we are setting a variable of myNumber to 100, then we will run an if statement to check if myNumber is over 50. If it is, we print “This is a high number”, otherwise we will print “That is a low number”. Don’t forget to save and then run the program, as you did with the previous examples.

Beginner's guide to Python on Mac: Set up, coding basics, training courses (8)

You will notice that the program prints out “This is a high number”, because our number is over 50. Feel free to change the number, and see what output you get.

Best Python training courses & learning resources

Now that you’ve got your feet wet, you might want to learn more about Python. Below, we have listed some of the best resources to get you on your way.

Udemy’s Python Bootcamp will teach you Python from the ground up. You will learn more about the Python syntax, build your own applications and games. A good way to go from beginner to professional.

Code Academy offer a fantastic range of coding courses, not just for Python but for most languages. The Python course will walk you through the basic syntax, functions, loops and even advanced topics.

Lynda offer a wide variety of tutorials and courses that will take your Python skills to the next level. Everything from Python basics, all the way to neural networks.

TutorialsPoint contains a large library of information on the Python syntax from beginner to advanced.

Learn Python the Hard Way. Don’t be intimidated by the title. This course teaches you the nuts and bolts of programming.

Think Python. This free book takes you through different aspects of the language.

Beginner's guide to Python on Mac: Set up, coding basics, training courses (2024)

FAQs

How do I start learning Python on Mac? ›

Your best way to get started with Python on macOS is through the IDLE integrated development environment; see section The IDE and use the Help menu when the IDE is running. If you want to run Python scripts from the Terminal window command line or from the Finder you first need an editor to create your script.

How to set up Python on Mac? ›

  1. Step 1: Check the Current Version of Python on Your System. ...
  2. Step 2: Visit the Python Website. ...
  3. Step 3: Download the macOS Installer. ...
  4. Step 4: Run the Installer and Follow the Instructions. ...
  5. Step 5: Verify Python and IDLE Are Installed Correctly. ...
  6. Step 6: Verify the Installation with Terminal.
Jan 16, 2024

Is Python easy to use on Mac? ›

Python comes pre-installed on Mac OS X so it is easy to start using. However, to take advantage of the latest versions of Python, you will need to download and install newer versions alongside the system ones. The easiest way to do that is to install one of the binary installers for OS X from the Python Download page.

What program to use for Python on Mac? ›

Try CodeRunner: Write, run, and debug from one app. When it comes to programming in Python on Mac, you can start writing useful scripts literally in any environment. Just open TextEdit available from the Applications folder and code away.

How long does it take to learn Python? ›

On average, it can take anywhere from five to 10 weeks to learn the basics of Python programming, including object-oriented programming, basic Python syntax, data types, loops, variables, and functions.

Do I need to install Python on my Mac? ›

Python is a powerful, general-purpose programming language that is widely used for web development, data science, artificial intelligence, and scientific computing. If you're new to programming and want to get started with Python, you'll need to install it on your computer.

How to setup Python and PyCHARM on Mac? ›

Installing Python on Mac
  1. Installing Python on Mac. Go to https://www.python.org/downloads/. ...
  2. Python should begin downloading the . ...
  3. Click on Continue.
  4. Select on which disk you intend to install Python.
  5. Click on Install.
  6. Installing PyCHARM on Mac. ...
  7. Click on the . ...
  8. Drag and drop the application into the Applications folder.

How to do coding in Mac? ›

Drag Visual Studio Code.app to the Applications folder, making it available in the macOS Launchpad. Open VS Code from the Applications folder, by double clicking the icon. Add VS Code to your Dock by right-clicking on the icon, located in the Dock, to bring up the context menu and choosing Options, Keep in Dock.

What is better for Python, Mac or Windows? ›

The platform doesn't matter with a language like Python. I use PCs because I use NVIDIA RTX cards in my workflow, but I know some who prefer to work on a 5k iMac because it takes up less space. Do what you like and don't let online people try to make you change your ways.

Is Python safe for Mac? ›

Even though there are many ways to install Python on macOS, the safest way is to use the official installer. However, you can also use a package manager for macOS like Homebrew—an application that makes it easy to install and manage software, dependencies, and other scripts on your computer.

What should I learn first before Python? ›

Python is beginner-friendly and many training options are available online, such as Python programming bootcamps and certificate programs. Before learning Python, it is beneficial to have basic computer literacy, strong communication skills, and a foundation in HTML and CSS.

How difficult is Python for beginners? ›

Python is widely considered among the easiest programming languages for beginners to learn. If you're interested in learning a programming language, Python is a good place to start. It's also one of the most widely used.

Where to practice Python coding? ›

7 Best Platforms to Practice Python
  1. Practice Python. If you're a beginner just starting out with Python, you'll find Practice Python helpful. ...
  2. Edabit. Edabit is a platform that offers a variety of programming challenges for multiple languages, including Python. ...
  3. CodeWars. ...
  4. Exercism. ...
  5. PYnative. ...
  6. Leetcode. ...
  7. HackerRank.
Apr 23, 2024

Is Python free for Mac? ›

Python is a free, open-source interpreted language that stands out for its versatility in supporting several programming paradigms, whether utilizing object-oriented language or imperative syntax, or using its command line to work in a functional way, as with languages like Haskell.

How do I start Python in terminal Mac? ›

How to Run a Python Script on Mac
  1. Open Launchpad.
  2. Search for terminal.
  3. Type Python --version in the terminal and press Enter, and you'll get an output stating the version of Python.
  4. Type python3 and press Enter to start coding in Python3 version.
  5. Write your code statement and press Enter to run it.

Does my Mac have Python? ›

To check if Python is installed on your macOS machine, follow these steps: Open the Terminal app by going to the Applications folder or Spotlight search and searching for Terminal. In the command line, type python3. If Python is installed, you should see a message like “Python 3.

How do I start Python 3 on Mac? ›

On MacOS, search for a program called terminal. You can do so by pressing the command key (⌘) + space bar. This will open up the Spotlight search bar, in which you start typing the word 'terminal'. Once you started the terminal, enter python3 to open the Python REPL.

Top Articles
Latest Posts
Article information

Author: Fr. Dewey Fisher

Last Updated:

Views: 6017

Rating: 4.1 / 5 (42 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Fr. Dewey Fisher

Birthday: 1993-03-26

Address: 917 Hyun Views, Rogahnmouth, KY 91013-8827

Phone: +5938540192553

Job: Administration Developer

Hobby: Embroidery, Horseback riding, Juggling, Urban exploration, Skiing, Cycling, Handball

Introduction: My name is Fr. Dewey Fisher, I am a powerful, open, faithful, combative, spotless, faithful, fair person who loves writing and wants to share my knowledge and understanding with you.