As I mentioned in a previous post, setting up a programming environment is the first step in learning Python. This time I’ll cover the process of installing and configuring an environment for Python 3 on the macOS Ventura operating system. I will also show how to start and configure the venv virtual environment to avoid conflicts with other Python modules. Finally, we will install the IDE, the VSCodium editor.
TABLE OF CONTENTS
Installing Python on macOS Ventura
Checking Python version
The system macOS Ventura does not come with a pre-installed version of Python 3. We can check this in the terminal with the command:
In macOS Ventura, we don’t even have the older version of Python that was available in previous versions of macOS.
As you can see above, we do not have any version of Python installed on MacOS Ventura. What’s more, when we try to check the Python 3 version, we can install the command line developer tools, which include Python 3 version 3.9.6.
We can also install the command line developer tools with the command:
After installation, this is how it looks to me on macOS Ventura:
Installing the latest Python version
Just a reminder that the latest version of Python is Python 3.11.3, which was released on 5 April 2023.
If we need the latest version of Python on macOS, there are two ways to do this.
The first way is to download the latest stable version of Python 3 from the python.org website and install it on our system. The exact address from which to download the macOS version of Python is:
The second way is to install Python 3 using the HomeBrew package manager. HomeBrew is open source software that allows you to install packages and tools not provided by Apple.
According to the brew.sh page, we need to run the command in the terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
After installation, we need to add the Homebrew location to your $PATH. The commands to do this are listed in the Homebrew installation summary. In my case the commands were as follows:
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/zibi/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
Homebrew is now installed and configured. We can now proceed to install the latest version of Python.
It is worth checking for updates before installing the software, using the command:
brew update && brew upgrade
We can check the available versions of Python:
brew search python
And we install the latest version of Python 3:
brew install email@example.com
Finally, we check that the new Python is installed:
Unlike installing Python on Ubuntu here, you simply restart the terminal so that the latest version of Python is available under the python3 command, i.e:
So we installed the latest Python 3.11.3
venv – Virtual Environment on macOS Ventura
A virtual environment is an isolated place where different versions of Python and its modules can be installed and used without conflict with other installed modules. This allows us to work on different projects in different environments and avoid the problems associated with different conflicts between those projects.
The necessary packages for the venv virtual environment are already installed, so let’s create a new directory and go there:
In my case, this is the LearnPython directory, where I will store the virtual environment.
We run the venv virtual environment on macOS in the same way as on Ubuntu. First, we create the virtual environment with the command:
python3 -m venv my_venv
I have named my environment my_venv, but any other name can be used.
We then activate the virtual environment we have created:
This is the command line after enabling the virtual environment:
(my_venv) zibi@MaC LearnPython %
The name of the environment my_venv, is in parentheses at the beginning.
We can also confirm that we are in a virtual environment by checking the location of the Python interpreter:
The resulting location shows that Python is in our running environment.
In a virtual environment, we can use the python command instead of python3 if that’s what we prefer. Outside the environment, we use only the python3 command.
If we want to leave the virtual environment, use the command:
This is how it looks for me on macOS Ventura:
IDE – Installing VSCodium on macOS Ventura
IDE (Integrated Development Environment) is a set of useful programs combined into a single graphical interface, giving you a range of useful tools to help you write correct code.
VSCodium is a clone of Microsoft’s popular Visual Studio Code editor. It looks and works exactly like VS Code, except that VSCodium doesn’t track users because it doesn’t include Microsoft’s tracking and telemetry add-ons.
The easiest way to install VSCodium on macOS Ventura is to use the homebrew manager. I have shown the homebrew installation process above when installing Python 3.11.
So VSCodium installations are done with the command:
brew install --cask vscodium
After installation, from the list of installed applications in the Launchpad or in the Applications folder, we can search for the VSCodium editor and start it. VSCodium can also be started from a terminal with the command:
If the message “VSCodium” can’t be opened because Apple cannot check it for malicious software.” appears when launching VSCodium, i.e. as shown below:
This selects “Show in Finder”, then right click on VSCodium and select “Open”. This will give us the option to open the application.
The subsequent launch of VSCodium runs without problems.