How to Install python on Mac
The best way we found to install Python 3 on macOS is through the Homebrew package manager.
There are following steps which are used while installing Python3 on MacOS.
Prerequisites
- MacOS
- Login as an administrator on terminal
Installation
1) Checking python’s version on the system
We can check which version of the Python is currently installed on our system. Generally, Python 2.7 is installed by default.
Let’s see how can we do it.
$ python -version
Macos Python 1
It shows Python 2.7.10 is installed on the computer which is quite often.
2) Download Python 3.6.3
In order to install Python 3.6.3, we must download the latest version from its official website https://www.python.org/downloads/ . The file is downloaded in .pkg format which can be directly installed by using Installer command.
3) Install Python 3.6.3
Since the downloaded file already is in .pkg format hence no mounting is required and We can use installer command to install Python 3.6.3.
Also Read : How to install python on windows
Let’s see how can we do it.
Macos Python 2
Since The installer is used with super user permissions hence sudo forces terminal to prompt the user to fill the admin password. The process installs the Python 3.6.3 to the root directory which is mentioned with the target option.
4) Verify Python3
To check which Python version is installed on the machine, we can use python -version command. Since by default installed version is Python 2.7.10 hence it shows python 2.7.10. but it gives us flexibility to check the version of Python 3 on our computer.
Let’s see how can we use python 3 to check which version of python 3 is running.
$ python -version
5) Working on Python’s script mode
To work on Python command line, we simply type python3 on the terminal. Python shell open where we can run Python statements such as print statements as we did here.
Macos Python 3
To run a Python file (.py) on the terminal, we simply type the file name and the file will be interpreted.
Well, we have installed Python3 on our MacOS.
The best way we found to install Python 3 on macOS is through the Homebrew package manager.
Step 1: Install Homebrew (Part 1)
To get started, you first want to install Homebrew:
Open a browser and navigate to http://brew.sh/. After the page has finished loading, select the Homebrew bootstrap code under “Install Homebrew”. Then hit Cmd+C to copy it to the clipboard. Make sure you’ve captured the text of the complete command because otherwise the installation will fail.
Now you need to open a Terminal.app window, paste the Homebrew bootstrap code, and then hit Enter. This will begin the Homebrew installation.
If you’re doing this on a fresh install of macOS, you may get a pop up alert asking you to install Apple’s “command line developer tools”. You’ll need those to continue with the installation, so please confirm the dialog box by clicking on “Install”.
At this point, you’re likely waiting for the command line developer tools to finish installing, and that’s going to take a few minutes. Time to grab a coffee or tea!
Step 2: Install Homebrew (Part 2)
You can continue installing Homebrew and then Python after the command line developer tools installation is complete:
Confirm the “The software was installed” dialog from the developer tools installer.
Back in the terminal, hit Enter to continue with the Homebrew installation.
Homebrew asks you to enter your password so it can finalize the installation. Enter your user account password and hit Enter to continue.
Depending on your internet connection, Homebrew will take a few minutes to download its required files. Once the installation is complete, you’ll end up back at the command prompt in your terminal window.
Whew! Now that the Homebrew package manager is set up, let’s continue on with installing Python 3 on your system.
Step 3: Install Python
Once Homebrew has finished installing, return to your terminal and run the following command:
$ brew install python3
Note: When you copy this command, be sure you don’t include the $ character at the beginning. That’s just an indicator that this is a console command.
This will download and install the latest version of Python. After the Homebrew brew install command finishes, Python 3 should be installed on your system.
You can make sure everything went correctly by testing if Python can be accessed from the terminal:
Open the terminal by launching Terminal.app.
Type pip3 and hit Enter.
You should see the help text from Python’s “Pip” package manager. If you get an error message running pip3, go through the Python install steps again to make sure you have a working Python installation.
Assuming everything went well and you saw the output from Pip in your command prompt window…congratulations! You just installed Python on your system, and you’re all set to continue with the next section in this tutorial.
Discover more from mycodetips
Subscribe to get the latest posts sent to your email.