Tutorial: Installing Python on Mac

Tutorial: Installing Python on Mac

Installing Python on Mac Python is one of the most brawny scheduling languages, by and large used in data science, machine eruditeness, and big data analytics. so, installing Python is essential for all programmers. As a novitiate programmer, you may be wondering how to install or update Python on your Mac properly. here, we will walk through the different ways of install and update Python on macOS .
then, to write and run our Python code in an integrated development environment ( IDE ), we will learn how to install and configure ocular Studio Code on Mac. There are unlike methods for installing and updating Python on Mac, but let ’ s stick to the third principle of the Zen of Python that says : “ Simple is better than complex. ” Accordingly, we will try dim-witted methods preferably than complex ones. Before we jump into learning how to install or update Python on Mac, let ’ s review what we ’ ra going to discuss in this tutorial :

Installing and Updating Python on Mac

I have two pieces of news for you ; one is good, the early bad. The good newsworthiness is that for the sake of compatibility with bequest systems, Python 2.7 is pre-installed on your Mac, but the regretful newsworthiness is that Python 2.7 has been retired. consequently, it isn ’ triiodothyronine recommended for fresh developments. so, if you want to take 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 we start installing the latest translation of Python, let ’ s see why there are unlike versions of the like program lyric. All program languages evolve by adding raw features over fourth dimension. The program lyric developers announce these changes and improvements by increasing the version count .

Install Python 3 as a part of the Command Line Developer Tools

To check the current version of Python that is already installed, open the Terminal application by typing command + space and then spelling out terminal and hitting render. immediately, type the pursuit command, and then hit reappearance to see that you have Python 2.7 pre-installed on your macintosh :

% python --version
Python 2.7.18
now, try the follow command to check whether or not Python 3 is installed on your macintosh :
~ % python3 --version
The adopt message will probably appear on the Terminal window ,
xcode-select: note: no developer tools were found at '/Applications/Xcode.app', requesting install. Choose an option in the dialog to download the command line developer tools.
And alongside the Terminal window, a dialogue box will mechanically appear that says this command requires the command pipeline developer tools. First, let ’ s identify the command-line developer tools. To put it concisely, the control line developer tools box is a set of tools by and large used in the development process. They help run specific commands, such as make, rotter, python3, etc. sol, although there are other ways to install Python 3.x on Mac without installing the command line developer tools, I recommend you install it because it provides a string of tools for development on Mac. To install the software, snap on the Install push button, and follow the steps to complete the facility summons. Once the facility process is complete, rerun the previous control. Yes, Python 3.x is installed on your Mac .
~ % python3 --version
Python 3.8.9

Install Python 3 with the Official Installer

Downloading the latest python version from the official Python web site ( python.org ) is the most common ( and recommended ) method for installing Python on a Mac. Let ’ s try it out .
1. First, download an installer software from the Python web site. To do that, visit hypertext transfer protocol : //www.python.org/downloads/ on your Mac ; it detects your engage system automatically and shows a big button for downloading the latest adaptation of Python installer on your Mac. If it doesn ’ thyroxine, click the macOS associate and choose the latest Python release.
Installing Python on Mac
2. once the download is complete, double-click the software to start installing Python. The installer will walk you through a charming to complete the facility, and in most cases, the nonpayment settings work well, so install it like the other applications on macOS. You may besides have to enter your Mac password to let it know that you agree with installing Python.
Installing Python on Mac
NOTE If you ’ rhenium using Apple M1 Mac, you need to install Rosetta. Rosetta enables Intel-based features to run on Apple silicon Macs .
3. When the facility completes, it will open up the Python booklet.
Installing Python on Mac
4. Let ’ s verify that the latest version of Python and IDLE installed correctly. To do that, double-click IDLE, which is the integrate exploitation environment shipped with Python. If everything works correctly, IDLE shows the Python shell as follows :
Installing Python on Mac
5. Let ’ s write a simple Python code and run it in IDLE. Type the trace statement, and hit the return key .

print(“Hello, World!”)

Installing Python on Mac
Or let ’ s do a basic calculation in Python as follows :
Installing Python on Mac

NOTE The stimulate advantage of this installation method acting is that you can well update an outdated Python install by downloading the latest Python installer. The new version of Python is available on your Mac once the initiation is complete .

Installing Visual Studio Code on Mac

Although we can use IDLE or the terminal lotion for writing Python scripts, we prefer to use a herculean, extensile, and lightweight code editor rather than rigid coding environments. In this share of the tutorial, we ’ re going to install ocular Studio Code for Python development on macOS .
1. First, you need to download ocular Studio Code for macOS from its official web site at hypertext transfer protocol : //code.visualstudio.com/.
Installing Visual Studio Code on Mac
2. Double-click the download file to extract the archive contents.
Installing Visual Studio Code on Mac
3. Move the ocular Studio Code application to the Application folder to make it available in the macOS launching pad.
Installing Visual Studio Code on Mac
4. plunge ocular Studio Code, and then open a booklet where your Python scripts exist ( or create a new one ). For example, create a new booklet on your Desktop, and diagnose it py_scripts, then try to open the folder on VS Code. normally, VS Code needs your permission to access files in your Desktop booklet ; snap OK.
Installing Visual Studio Code on Mac

besides, you may need to declare that you trust the authors of the files stored in your Desktop booklet.
Installing Visual Studio Code on Mac
5. Create a new file with a .py extension. For example, create a newfangled file, and name it prog_01.py. VS Code detects the .py extension and wants to install a Python extension.
Installing Python on Mac
To work with Python inside VS Code, we need to use the Python reference, which includes many utilitarian features, such as code completion with IntelliSense, debugging, unit testing support, etc .
Install it by clicking on the Install push button.
Installing Python on Mac

We can besides install the Python extension by browsing extensions. Click on the Extensions picture on the leave side of VS Code.
Installing Python on Mac
This will show you a list of the most popular VS Code extensions on the VS Code Marketplace. immediately, we can select the Python extension and install it.
Installing Python on Mac

6. once the elongation is installed, you have to select a Python spokesperson. Click on the Select Python Interpreter button :
Installing Python on Mac
then select the commend Python interpreter on the list.
Installing Python on Mac

If you have multiple Python versions installed on your Mac, it ’ sulfur better to choose the latest version.
Installing Python on Mac

You besides can select a Python interpreter using the Python : choose Interpreter command from the Command Palette. To do indeed, press CMD + SHIFT + P, type Python, and choose Select Interpreter .

Running Our First Python Script on Mac

excellent, we have everything we need to write and run our Python code inside VS Code. Let ’ s write the follow code in VS Code and then run it .

print("Hello, World!)
name = input("What's your name? ")
print("Hello {}!\nWelcome to Dataquest!".format(name))

Run the code by clicking the ▶️ push button at the top correct corner of VS Code. First, it shows Hello, World ! in the integrated terminal, then it asks your name ; enter your name, and hit render. It outputs Hello , and writes Welcome to Dataquest! on the adjacent line .
Installing Python on Mac

Conclusion

In this tutorial, we learned how to install the latest interpretation of Python on Mac, arsenic well as updating an outdated Python adaptation. additionally, we learned how to install ocular Studio Code as a code editor program and configure it for running Python scripts. ultimately, we wrote a little Python script in VS Code and ran it successfully. In the future tutorial, we will learn about Python virtual environments and how to create and use them. Congratulations ! From now on, the sky ’ s the limit, and you can become a great Pythonista !

Tags

Mehdi Lotfinejad
About the generator

Mehdi Lotfinejad

Mehdi is a Senior Data Engineer and Team Lead at ADA. He is a professional flight simulator who loves writing data analytics tutorials .

informant : https://thefartiste.com
Category : Tech

About admin

I am the owner of the website thefartiste.com, my purpose is to bring all the most useful information to users.

Check Also

articlewriting1

How to Show Profile Picture Instead of Video in Zoom Meeting

Zoom is a democratic and utilitarian outside meet and television conferencing tool. however, not everyone …

Leave a Reply

Your email address will not be published.