Set up python environment on macOS

Wanted to dig into python programming language a little bit deeper to explore its potentials, so log all steps I made to set up python environment on a macOS

Install python package for macOS

Python can be downloaded from its official site, once have the package downloaded, double click and follow the installation guide to complete the install

Verify install

Once install complete, open your terminal app and type below command

python3 --version

Should have the python version output as below example which indicates you have python installed successfully

Mac-Pro ~ % python3 --version
Python 3.12.1

And you can play around with it by following its official doc

Create a virtual environment

Click here to find out whether you need to create a virtual environment when you do python development

Create a folder where you want to play with python, eg, my-python-app

Go to my-python-app folder and run below commands to create a virtual environment

# create-venv.sh
python3 -m venv my-venv
source my-venv/bin/activate

Python package installer

Pip is a package installer for Python, there’re two ways of installing pip as its official site documented

  • ensurepip
  • get-pip.py
Use ensurepip module
python3 -m ensurepip --upgrade

Example output

Mac-Pro ~ % python3 -m ensurepip --upgrade
Requirement already satisfied: pip in /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages (23.2.1)

Verify pip installation

pip3 --version

Example output

Mac-Pro ~ % pip3 --version
pip 23.2.1 from /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pip (python 3.12)
Use get-pip.py

Download get-pip.py

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

and run install command

python3 get-pip.py

Now you should have python environment set up ready, time to start python journey.

Reference

Leave a Comment

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

Scroll to Top