Installing Python (Optional For Mac Users) - Coursera

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

7/23/23, 12:14 PM Installing Python (optional for Mac users) | Coursera

1. Django Web Framework


2. Week3.1Installing Python (optional for Mac users)

Previous Next

Menu

Installing Python (optional for Mac users)


An Apple Mac, by default, comes with Python version 2.7 installed. You can verify this by opening up a terminal and running the following command: 

1 python --version 

To follow and complete the lessons in this course, you will need Python 3. 

Before you can install Python, you will need to install a few dependencies. These are Xcode and brew. You will find details of these in the Required Dependencies reading.
The Mac has various ways to carry out software installations, the most common way is to use the package manager called brew to handle the installs. Make sure you have
Homebrew installed on your local machine.

Once the dependencies are installed, you can begin to install Python. Run the following command: 

1 brew install python

file:///Users/alaaalbarazi/Library/CloudStorage/Box-Box/ITCourses/Django/Installing Python (optional for Mac users) _ Coursera.html 1/683


7/23/23, 12:14 PM Installing Python (optional for Mac users) | Coursera

Mac automatically comes with version 2.7 by default. When you install Python via brew, it will install version 3.x. To verify that you have both versions installed, run the
following:

1 python --version 
2 python --version 

1 python3 --version 

If you experience any challenges with the versions above, you may also need to run the command using the root user such as:

1 sudo python –version

1 sudo python3 –version

The result displays:

To reduce confusion, you need to set the paths to point to the brew install of python3.

First, let's figure out where the package manager brew installed it. Run the following command: 

1 brew info python 

1 brew info python3

file:///Users/alaaalbarazi/Library/CloudStorage/Box-Box/ITCourses/Django/Installing Python (optional for Mac users) _ Coursera.html 2/683


7/23/23, 12:14 PM Installing Python (optional for Mac users) | Coursera

Below is the output of the above command:

The section you may be interested in is where it was installed. 

Unversionedsymlinks `python`, `python-config`, `pip` etc. pointing to `python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/opt/homebrew/opt/[email protected]/libexec/bin 

The /opt/homebrew/opt/[email protected]/libexec/bin is the one you want to use and set for our path. Copy it from the terminal. The following steps may vary depending on
the Mac OS you are running. 

Zsh
1 vim ~/.zshrc
Vim .zshrc
# no need for ~/
Bash 
1 vim ~/.bashrc

Vim is a text editor that allows you to change files directly from the shell. To make the edits: 

1. Press the I key on your keyboard. 

2. Add the following line and remember to replace 3.x with the python version that was installed on your system:

shell PATH="/opt/homebrew/opt/[email protected]/libexec/bin:${PATH}" OR

export PATH="/opt/homebrew/opt/[email protected]/libexec/bin:${PATH}

1. Press the esc button to exit from insert mode. 


file:///Users/alaaalbarazi/Library/CloudStorage/Box-Box/ITCourses/Django/Installing Python (optional for Mac users) _ Coursera.html 3/683
7/23/23, 12:14 PM Installing Python (optional for Mac users) | Coursera
2. Hold down the Shift Key and press the colon button represented by &;

3. Type wq! and then press the Enter key to exit vim. 

4. Run the following command:  Zshshell: source ~/.zshrc Bashshell: source ~/.bashrc

5. To verify everything is working as you would expect, run the following command: shell python --version Python 3.9.10

6. You should see the output similar to the above, depending on your install version.

The list of commands relevant to vim can be found in the Course Introduction’s Additional Resources for this Lesson.

On completion of this reading, you will be able to identify any required dependencies for your operating system.

Setting up Python on Windows is straightforward and will install without any required dependencies. On Mac, however, you do need some additional dependencies
prior to installing Python.

Xcode
To install brew, you need to install Xcode first. Homebrew does not come with its own compiler and it needs Xcode installed for it to work correctly. To install Xcode do
the following:

Open a terminal, and run the following command: 

1 shell xcode-select --install 

A pop-up box will appear asking you to confirm the installation. Click on the Install button. 

Agree to the license agreement. 

brew
Mac's do not come with package managers like most Linux distributions. To make up for this an external tool called brew was created. To install brew, do the following:

1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 

Go to next item
Completed
Like Dislike Report an issue

file:///Users/alaaalbarazi/Library/CloudStorage/Box-Box/ITCourses/Django/Installing Python (optional for Mac users) _ Coursera.html 4/683

You might also like