How To Install, Upgrade Python and Run VENV on MAC
Learn how install, upgrade Python on MAC and use VENV for your projects with this easy steps.
Join BitBuddies
Level up your DevOps skills with hands-on courses on CloudPanel and Dockploy. Join our community of developers and get expert workshops to accelerate your online journey.
Start your journey to DevOps mastery today! π
Virtual environments in Python are a crucial tool for managing project-specific dependencies and avoiding conflicts with system-wide installations. They allow developers to work with isolated Python environments, ensuring that each project has its own set of dependencies that do not interfere with others. This article will guide you through the process of installing, upgrading, and running Python virtual environments (venv) on macOS using Homebrew, a popular package manager for macOS.
Install Brew on MAC
Homebrew is an open-source package manager for macOS that simplifies the installation of software on Appleβs operating system. To install Homebrew, open the Terminal app and enter the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
This command downloads and runs the Homebrew installation script.
Install Latest Python on MAC with BREW
Once Homebrew is installed, you can easily install the latest version of Python. To do so, run the following command in your terminal:
brew install python
This command installs the latest stable version of Python, along with pip, setuptools, and wheel, which are tools for managing Python packages.
Check the version that is in use:
β― python3 -V
Python 3.11.6
Install Specific Version of Python on MAC with BREW
If you need a specific version of Python, Homebrew can help you install it. First, search for the available Python versions using:
brew search python
Output:
β― brew search python
==> Formulae
app-engine-python python-argcomplete python-gdbm@3.12 python-packaging python-tabulate python-yq wxpython
boost-python3 python-build python-idna python-ply python-tk@3.10 python@3.10 β pythran
bpython python-chardet python-kiwisolver python-psutil python-tk@3.11 python@3.11 β jython
cyclonedx-python python-charset-normalizer python-launcher python-pyparsing python-tk@3.12 python@3.12 β cython
ipython python-cycler python-lsp-server python-pytz β python-tk@3.9 python@3.7
meson-python python-dateutil python-lxml python-requests python-trove-classifiers python@3.8
micropython python-flit-core python-markdown python-setuptools β python-typing-extensions python@3.9 β
ptpython python-gdbm@3.11 python-matplotlib python-setuptools-scm python-urllib3 reorder-python-imports
Then, install the desired version, for example, Python 3.10:
brew install python@3.10
After installation, you may need to link the Python version if itβs not already in your PATH:
brew link python@3.10
Then you can use the version to run your python app with:
β― python3.10 -V
Python 3.10.14
Upgrade Python to Latest Version on MAC
To upgrade Python to the latest version available in Homebrew, first update Homebrew itself:
brew update
Then, upgrade Python:
brew upgrade python
Output:
β― python3 -V
Python 3.12.2
This will upgrade Python to the latest version provided by Homebrew.
If you are interested in creating some Python projects you can check the below article to get started:
- NiceGUI For Beginners: Build An UI to Python App in 5 Minutes
- How To Add Multiple Pages to NiceGUI
- How To Run Any Python App in Docker with Docker Compose
Run Python in VENV on MAC
To create a virtual environment in Python, navigate to your project directory and run the following command:
python3 -m venv myenv
Replace myenv with your preferred environment name. This command creates a new virtual environment directory myenv within your project[6].
To activate the virtual environment, use:
source myenv/bin/activate
Once activated, your terminal prompt will change to indicate that you are working inside the virtual environment. You can now install packages locally within this environment without affecting the global Python installation.
To deactivate the virtual environment and return to the global Python context, simply run:
deactivate
Conclusions
Managing Python environments with venv on macOS is straightforward, especially with the help of Homebrew. By following the steps outlined in this article, you can install and manage multiple versions of Python, create isolated environments for your projects, and ensure a clean and conflict-free development experience. Remember to activate the appropriate virtual environment before working on a project to keep dependencies organized and projects running smoothly.
Related Posts
Bulk URL Checker with uv: Validate Website Accessibility in Python
Learn how to build a powerful URL checker script using uv that validates multiple websites concurrently, detects broken links, and generates detailed reports.
How to Use Any OpenRouter Model with Google Agent Development Kit (ADK)
See how you can use any model you want in Google Agent Development Kit (ADK) with LiteLLM. Configure OpenRouter models easy.
Getting Started with uv: Setting Up Your Python Project in 2025
See how you can get started with uv, a next-generation Python package and project manager written in Rust by the Astral team.