Upgrading from Python2 to Python3 on MacOS
Last Updated :
03 Jun, 2024
Python is a high level and general-purpose programming language. It is widely used in a variety of fields such that it fulfills the need of developers who are in the front end, backend, or both. It is being used rigorously in Machine Learning, Artificial Intelligence, Web Development, and in various other domains.
But, there's an issue that mac devices come with python 2 as default and you cannot use Python 3 as your default in your device. In this article, we will look into the steps of changing the default python setting to Python 3 and discuss its pros and cons.
Disadvantages of Python 2:
Following are the list of disadvantages of using Python 2 on your Mac machine:
- The primary reason to get rid of Python 2 is that it is already discontinued since January 1, 2020.
- Community support of Python 2 is catastrophically decreasing.
- Syntax of Python 2 is comparatively difficult to understand.
- To store Unicode string value, you need to define them with "u".
- For iteration, xrange() is used.
- Rules of ordering comparison are quite complex.
Advantages of Python 3 over Python 2:
The following list states the advantages of Python 3 over Python 2:
- Since Python 2 is discontinued and no more development will be carried out in Python 2 so sticking to Python 2 makes no sense. So, Python is obviously a go-to option.
- Community support of Python 3 is incredible.
- Syntax of Python 3 is made much simpler and understandable.
- Python 3 stores Unicode string value as default.
- For iteration, range() is used.
- We can port Python 2 to Python 3 but it is not that reliable.
- Rules of ordering comparison have been simplified.
- Library support of Python 3 is just fabulous.
And several more features are added as time is passing by, to read more on the difference between the Python 2 and Python 3 refer to this GeeksforGeeks article. Many of you must have installed python 3 from (python.org) but still, it might be showing python version is python 2. To make sure that this fact is true or not check your python version by running the below command in your terminal:
python --version
Output:
Check Python VersionTo get rid of this issue follow the steps given below:
Installing Python 3 on the system:
Step 1: Firstly we have to change the Login Shell from Bash to Zsh. To change it navigate to System preferences and click on Users and Groups. Now Click on the Lock Icon and authenticate with your credentials. After authentication right-click on the current user and select Advanced Options and change the login shell from /bin/bash to /bin/zsh.
At this stage, you will find your Terminal shell is changed from bash shell to Zsh shell.
Confirm whether your bash is converted to zsh shellStep 2: Now you have to install Xcode from the App Store. To install Xcode, go to App Store and search for Xcode. Now click on get and click on the Install button to get Xcode.
Installing XCodeStep 3: After installing Xcode you'll have to install the command-line tool for mac using the below command:Â
xcode-select --install
Now click on the Install button and Agree to the terms and condition when a window pops up as shown below:
Installing the Command Line ToolStep 4: Now you'll have to install a package manager (eg: HomeBrew, MacPorts, Fink, etc) for mac which makes the installation process really easy and hassle-free. Here we are using HomeBrew Package Manager. To install this run the below command in your terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh
Installing HomeBrew Package ManagerYou can also manually install it from the link.
Step 5: Now we are all set to install python, To install python use the below command and press Enter:
brew install python
This will take some time to install python in your system. This command will install the latest version of Python.
Installing PythonSetting Python 3 as Default:
To set Python 3 as a default on your Mac system, follow the below steps:
Step 1: Copy the path of the directory where Python is installed as shown below:
Python 3 PathStep 2: Run ls -a command in your terminal but make sure that you are in your home directory or simply run the cd ~ command to move to the home directory.
Listing all the hidden files using this commandStep 3: Now we have to create a file by using the vim .zshrc  command to overwrite the path so that python 3 becomes the default.
Creating a file named .zshrcStep 4: To write in the file press 'i' from the keyboard to go to insert mode. Now add the path using the below command:
export PATH=copied path from the above point:$PATH
 Now to save it press ESC and write (:wq) and press Enter. And we are done.
Overwriting the Path of Python 2 with the Path of Python 3Step 5: Quit the terminal for the changes to take place and now write the python command to see that now python 3 is set as your default python for your mac device.
Confirmation of Python 3 versionÂ
Similar Reads
How to Install Pytest For Python3 On MacOS? The pytest framework is used to write small tests simple, but it can also handle complex functional testing for applications and libraries. The tests are expressive and readable. Or we can say that this framework is used to write test codes with the help of Python language. It is generally used to w
2 min read
How to Upgrade Pip and Python on Windows, Linux, and MacOS? Python is a programming language with standard libraries and a great ecosystem of third-party packages. On the other side, Pip is the default package manager for Python that installs, upgrades and manages Python, including its dependencies. Pip simplifies the process of installing external libraries
5 min read
Automate the Conversion from Python2 to Python3 We can convert Python2 scripts to Python3 scripts by using 2to3 module. It changes Python2 syntax to Python3 syntax. We can change all the files in a particular folder from python2 to python3. Installation This module does not come built-in with Python. To install this type the below command in the
1 min read
How to Install Turtle in Python on MacOS? Turtle is a Library of Python Language. Turtle graphics is the best way to introduce programming to kids. We can design pictures and create shapes on a virtual canvas provided by a turtle. Installing the Turtle Package on MacOS using PIP To install Turtle Package on MacOS follow these steps: Step 1:
1 min read
Upgrade Opencv Using Python PIP In this article, we will guide you through the step-by-step process of upgrading OpenCV to a specific version using Python PIP. What is Python OpenCV?OpenCV, or Open Source Computer Vision Library, is an open-source software developed by Intel for computer vision, image processing, and machine learn
3 min read