Download Python for Mac Os X
Tutorial: Installing Python on Mac
Published: January 12, 2022

Python is i of the nearly powerful programming languages, more often than not used in data science, machine learning, and big information analytics. And then, installing Python is essential for all programmers. Every bit a novice programmer, y'all may be wondering how to install or update Python on your Mac properly. Hither, we will walk through the different ways of installing and updating Python on macOS.
Then, to write and run our Python code in an integrated development environs (IDE), we will learn how to install and configure Visual Studio Lawmaking on Mac. In that location are different methods for installing and updating Python on Mac, merely allow's stick to the 3rd principle of the Zen of Python that says: "Simple is better than complex." Accordingly, we will try elementary methods rather than circuitous ones. Before nosotros jump into learning how to install or update Python on Mac, permit'southward review what nosotros're going to hash out in this tutorial:
- Installing and updating Python on Mac
- Installing Visual Studio Code on Mac
- Running our kickoff Python script on Mac
Installing and Updating Python on Mac
I have two pieces of news for you; one is adept, the other bad. The expert news is that for the sake of compatibility with legacy systems, Python two.7 is pre-installed on your Mac, but the bad news is that Python two.seven has been retired. Therefore, it isn't recommended for new developments. So, if you want to accept advantage of the new Python version with its many features and improvements, you need to install the latest Python alongside the version that comes pre-installed on macOS. Before nosotros start installing the latest version of Python, let's run into why at that place are different versions of the same programming linguistic communication. All programming languages evolve past adding new features over time. The programming linguistic communication developers announce these changes and improvements past increasing the version number.
Install Python three as a office of the Control Line Developer Tools
To bank check the current version of Python that is already installed, open the Terminal application past typing command + space and and so spelling out terminal and striking render. Now, type the following command, so hit return to run across that y'all accept Python 2.7 pre-installed on your Mac:
% python --version
Python 2.7.18
Now, effort the following command to cheque whether or not Python 3 is installed on your Mac:
~ % python3 --version
The post-obit message will probably announced on the Last window,
xcode-select: notation: no developer tools were found at '/Applications/Xcode.app', requesting install. Choose an selection in the dialog to download the control line developer tools.
And aslope the Final window, a dialog box will automatically appear that says this command requires the control line developer tools. Commencement, let's place the command-line developer tools. To put it briefly, the command line developer tools parcel is a set of tools mostly used in the evolution process. They assist run specific commands, such as brand, git, python3, etc. So, although there are other ways to install Python 3.x on Mac without installing the command line programmer tools, I recommend you lot install it because it provides a cord of tools for development on Mac. To install the bundle, click on the Install button, and follow the steps to consummate the installation process. Once the installation process is complete, rerun the previous command. Yep, Python 3.ten is installed on your Mac.
~ % python3 --version
Python 3.eight.ix
Install Python three with the Official Installer
Downloading the latest Python version from the official Python website (python.org) is the most common (and recommended) method for installing Python on a Mac. Let'south endeavour information technology out.
1. Commencement, download an installer parcel from the Python website. To do that, visit https://www.python.org/downloads/ on your Mac; it detects your operating system automatically and shows a big button for downloading the latest version of Python installer on your Mac. If it doesn't, click the macOS link and choose the latest Python release.
ii. Once the download is complete, double-click the bundle to starting time installing Python. The installer volition walk yous through a magician to complete the installation, and in virtually cases, the default settings work well, so install it similar the other applications on macOS. You may also accept to enter your Mac password to let it know that you hold with installing Python.
Notation If you're using Apple M1 Mac, yous need to install Rosetta. Rosetta enables Intel-based features to run on Apple silicon Macs.
3. When the installation completes, it will open the Python binder.
iv. Let'southward verify that the latest version of Python and IDLE installed correctly. To do that, double-click IDLE, which is the integrated development environment shipped with Python. If everything works correctly, IDLE shows the Python vanquish as follows:
5. Let's write a simple Python code and run it in IDLE. Blazon the following argument, and hitting the render key.
print("Hello, World!")
Or let's do a bones calculation in Python equally follows:
Note The heady advantage of this installation method is that you tin can hands update an outdated Python install by downloading the latest Python installer. The new version of Python is available on your Mac once the installation is consummate.
Installing Visual Studio Code on Mac
Although we can employ IDLE or the terminal application for writing Python scripts, we prefer to use a powerful, extensible, and lightweight lawmaking editor rather than rigid coding environments. In this part of the tutorial, nosotros're going to install Visual Studio Lawmaking for Python development on macOS.
ane. First, yous need to download Visual Studio Lawmaking for macOS from its official website at https://code.visualstudio.com/.
2. Double-click the downloaded file to extract the archived contents.
3. Motility the Visual Studio Code application to the Awarding binder to get in available in the macOS launchpad.
4. Launch Visual Studio Code, and and so open a folder where your Python scripts exist (or create a new 1). For instance, create a new binder on your Desktop, and name it py_scripts
, then try to open the folder on VS Code. Usually, VS Code needs your permission to access files in your Desktop folder; click OK.
Besides, you may demand to declare that you trust the authors of the files stored in your Desktop folder.
5. Create a new file with a .py
extension. For instance, create a new file, and proper noun it prog_01.py.
VS Lawmaking detects the .py
extension and wants to install a Python extension.
To piece of work with Python within VS Code, we need to use the Python extension, which includes many useful features, such as code completion with IntelliSense, debugging, unit of measurement testing back up, etc.
Install it past clicking on the Install push.
We tin can likewise install the Python extension by browsing extensions. Click on the Extensions icon on the left side of VS Code.
This will evidence you a list of the near popular VS Code extensions on the VS Code Marketplace. At present, nosotros tin can select the Python extension and install it.
vi. Once the extension is installed, yous have to select a Python interpreter. Click on the Select Python Interpreter button:
And so select the recommended Python interpreter on the listing.
If you lot have multiple Python versions installed on your Mac, information technology'due south better to choose the latest version.
Y'all besides tin select a Python interpreter using the Python: Select Interpreter command from the Command Palette. To do so, printing CMD + SHIFT + P, blazon Python, and choose Select Interpreter.
Running Our First Python Script on Mac
Excellent, we accept everything we demand to write and run our Python code inside VS Code. Let'due south write the following code in VS Lawmaking and so run it.
impress("Hello, World!) name = input("What'southward your proper noun? ") print("Hello {}!\nWelcome to Dataquest!".format(name))
Run the code by clicking the ▶️ button at the top right corner of VS Lawmaking. Get-go, it shows Hi, World! in the integrated terminal, then it asks your proper noun; enter your name, and hit return. Information technology outputs How-do-you-do <your name,>
, and writes Welcome to Dataquest!
on the side by side line.
Conclusion
In this tutorial, we learned how to install the latest version of Python on Mac, as well as updating an outdated Python version. Additionally, nosotros learned how to install Visual Studio Code as a code editor and configure it for running Python scripts. Finally, nosotros wrote a pocket-size Python script in VS Code and ran information technology successfully. In the next tutorial, nosotros will learn about Python virtual environments and how to create and use them. Congratulations! From now on, the heaven'southward the limit, and yous tin can become a dandy Pythonista!
Tags
Download Python for Mac Os X
Posted by: russellforyin1938.blogspot.com
Post a Comment