Python
Install
We will not be using Python that get added by installing the command-line tools with xcode-select --install
.
i.e., /Library/Developer/CommandLineTools/usr/bin/python3
Instead we will install latest Python3 and pip3 via brew
Apple does not include Python3 in the MacOS Sonoma distribution, but it get added when installing the command-line tools with:
xcode-select --install
install Python 3:
Configure
Unversioned symlinks python
, python-config
, pip
etc. pointing to
python3
, python3-config
, pip3
etc., respectively, have been installed into
$(brew --prefix python)/libexec/bin
e.g., /opt/homebrew/opt/python@3.11/libexec/bin
Make sure you added export PATH=$(brew --prefix python)/libexec/bin:$PATH
to ~/my/paths.zsh
You can install Python packages with pip3 install <package>
They will install into the site-package directory /opt/homebrew/lib/python3.11/site-packages
Pipenv & Virtual Environments
The next step is to install Pipenv, so you can install dependencies and manage virtual environments.
pipenv is a tool that combines virtualenv with pip, the Python package manager. you no longer use them separately. It is designed to be more user-friendly than using virtualenv and pip separately.
A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the Project X depends on version 1.x but, Project Y needs 4.x
dilemma, and keeps your global site-packages directory clean and manageable.
Use brew to install Pipenv:
Upgrade
Usage
Optional
Installing packages for your project
Pipenv manages dependencies on a per-project basis. To install packages, change into your project’s directory (or just an empty directory for this tutorial) and run:
To install a Python package for your project
Generally, keep both
Pipfile
andPipfile.lock
in version control.
Running your code
Last updated