Installing Python 3.12 and Django in my Macbook

date
May 20, 2024
slug
python3.12-Django
status
Published
tags
Software Engineering
type
Post
source
summary
How to install Python with brew & fix $PATH
When I install the latest macOS, open the terminal to run
python --version
I got this response, which is not good.
command not found: python

Install Python via brew

Pre-requisite: Make sure brew is installed.
brew install python
This will install the latest version of Python. Then run this
brew info python
look at this information
Python has been installed as /opt/homebrew/bin/python3 Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to `python3`, `python3-config`, `pip3` etc., respectively, have been installed into /opt/homebrew/opt/python@3.12/libexec/bin
Based on this info, Python 3.12 is installed on my Mac using Homebrew, and the unversioned symlinks have been set up.

Open bash or zsh config

Use zsh and VS Code, then run this:
code ~/.zshrc

Add Python to your $PATH

Add the following lines to the file from the brew info python output and saved it via VS Code:
export PATH="/opt/homebrew/opt/python@3.12/libexec/bin:$PATH"
reload the shell profile by running the following command:
source ~/.bash_profile
For zsh use this:
source ~/.zshrc
Verify that Python 3.12 is now the default version by running the following command:
python --version
It should display the version number of Python 3.12.5.

Django is a Python library not application

from terminal use this line and install one by one, this need to be done for every folder when you create a new project.
python3 -m venv path/to/venv source path/to/venv/bin/activate python3 -m pip install django
And I am ready!

© Christopher Huang 2021 - 2024