Setting up Python on Mac: Installation Instructions and Running Your First Script

This article guides new MacBook users on setting up Python, checking for existing Python versions, and installing it if necessary. It also provides a step-by-step guide to running your first Python script.
  Guest Contributor · 5 min read · Updated may 2023 · General Python Tutorials

Welcome! Meet our Python Code Assistant, your new coding buddy. Why wait? Start exploring now!

Apple’s MacBook is arguably the most efficient computer on the market. This computer offers optimized performance that does not drain its battery. Considering these benefits, it is no surprise that most programmers often opt for this machine.

Despite its efficiency, using a Mac for the first time can be somewhat overwhelming. The keys and their respective commands are different. As such, it may take substantial time for most people to adjust.

To enable new MacBook users to get up to speed, this article will share insights as to how people can set up Python on their computers. It will also share insights into running the first script.

Identify If Your MacBook Has Python 2.7

For a very long time, Python 2.7 has been part of the pre-installed programming languages on a MacBook. In 2019, however, Apple notified users that they would be removing this tool from its operating system. As a result, your Mac will not have this application pre-installed if you are running on an operating system that was released afterward.

On the other hand, people whose computers are running on an older operating system may have Python. So before you follow any steps on how to update your macOS, check if the tool is still there:

Launch the Terminal app on your computer. You can use Spotlight or Mac’s Launchpad. On the terminal or launchpad, enter the command below and click on return:

$ python --version

If there is a pre-installed version of Python on your computer, the system will show you results. Below is what the results will look like:

Furthermore, it is also possible that there may be multiple versions of Python on your computer. To check if this is the case, simply follow the steps highlighted above to search for possible versions of the tool on your computer.

The search results will be similar to the image below:

$ python3 --version

How to Install Python on Your Mac

Perhaps, you have followed the procedures above and did not get any favorable results. It may be because you are using a more recent OS version.

Not to worry, users can still get Python on their MacBooks. Despite removing this tool from its OS, Apple is still compatible with this programming language.

Therefore, interested individuals can still manually add this program to their computers. All they need to do is follow these steps:

  1. Download the Python app from the official Python website. This step is crucial and people should avoid third-party or pirated websites:
  2. Once the download is complete, double-click on the program to begin the installation. Python will provide you with on-screen instructions to make the process easier:

  3. The computer will open Python’s installation directory once the package is installed on your computer, users will see the necessary documentation in a new finder window.

Individuals can still check if they have correctly installed Python and the necessary development tools that developers will need. Simply check for the IDLE file and double-click on it.

If the installation is complete, IDLE will launch a new Python shell. Another way to confirm is by running a print() function in idle or the Python shell.

Running the First Scripts

So far, you have been able to successfully install Python and a code editor (such as VSCode). With these tools in place, the next step is to write your code. These are the steps to follow when you want to write your first scripts:

  1. After creating the new file, they must select a location to save the New File. Depending on the code editor, users may need to install a Python extension.
  2. Once you have created the file, write any basic Python code. Run it on your computer by selecting the “Play” button in the top right corner. If you correctly write your code, the integrated terminal will display the output:

You should check every detail of the code if the terminal does not display the desirable result. For the first scripts, users should stick to the basic command like Hello World. This is as shown below.

print('Hello, World!')

Before jumping into writing programs in Python, people should undertake Python tutorials with practical sessions. These are available on YouTube and many other resources. This approach is far more efficient than jumping into the deep end of the pool.

Conclusion

The Python programming language and the MacBook have a unique history. In this regard, it is far easier to write scripts on a macOS computer. Some older Apple computers even have the package pre-installed.

Those who have newer versions of the MacBook can easily install the tool without fuss. All they need to do is to download the software via the official website.

Happy coding ♥

Loved the article? You'll love our Code Converter even more! It's your secret weapon for effortless coding. Give it a whirl!

Sharing is caring!



Read Also



Comment panel

    Got a coding query or need some guidance before you comment? Check out our Python Code Assistant for expert advice and handy tips. It's like having a coding tutor right in your fingertips!