Last verified: March 2026 | Tested on FreeBSD 15.0-RELEASE, Python 3.11.15
FreeBSD ships without Python by default, but the ports and package collections offer multiple maintained versions ready to install. Whether you need Python for scripting, automation, or running web frameworks, getting it set up on FreeBSD 15 takes just a few commands. This guide covers installing Python 3, pip, virtual environments, and managing packages.
Install Python 3 on FreeBSD 15
FreeBSD’s pkg repository carries several Python versions simultaneously. Check what’s available before installing so you can pick the version that matches your project requirements.
pkg search ^python3
You should see multiple Python 3 releases in the output:
python310-3.10.20
python311-3.11.15
python312-3.12.13
python313-3.13.12
Python 3.11 is a solid choice for most workloads right now. It has widespread library support and long-term security updates. Install it with:
pkg install -y python311
Confirm the installation by checking the version:
python3.11 --version
The output should confirm Python 3.11.15:
Python 3.11.15
If you need a different version for compatibility reasons, just substitute the version number in the package name (e.g., python312 for Python 3.12). You can install multiple versions side by side on the same system without conflicts. For more on FreeBSD package management, see our guide on FreeBSD and OpenBSD package and service management.
Install pip on FreeBSD 15
Python’s package installer, pip, is shipped as a separate package on FreeBSD. Install the version that matches your Python release:
pkg install -y py311-pip
Verify that pip is installed and linked to the correct Python version:
pip-3.11 --version
You should see pip reporting the correct Python path:
pip 23.3.2 from /usr/local/lib/python3.11/site-packages/pip (python 3.11)
One thing to keep in mind: running pip as root to install packages system-wide can overwrite files managed by pkg. FreeBSD will warn you about this. The safer approach is to use virtual environments, which we cover next.
Using Virtual Environments
Virtual environments isolate project dependencies from the system Python installation. This prevents version conflicts between projects and avoids polluting the system packages. Python 3 includes the venv module out of the box, so no extra packages are needed.
Create a new virtual environment for your project:
python3.11 -m venv ~/myproject-env
Activate the environment. Once activated, python and pip commands inside the shell automatically point to the virtual environment’s copies:
source ~/myproject-env/bin/activate
Your shell prompt will change to show the environment name, confirming it’s active:
(myproject-env) user@freebsd:~
Inside the virtual environment, you can safely install packages without affecting anything outside it. When you’re done working, deactivate it with:
deactivate
In production, it’s good practice to create a dedicated virtual environment per application. This makes deployments reproducible and cleanup straightforward.
Install Packages with pip
With your virtual environment active, install packages from PyPI using pip. For example, to install the popular requests library:
pip install requests
You can install a specific version if your project requires it:
pip install requests==2.31.0
To see all installed packages and their versions in the current environment:
pip freeze
This output follows the format pip expects for requirements files, so you can export it directly:
pip freeze > requirements.txt
On another machine or in a fresh virtual environment, recreate the exact same set of dependencies with:
pip install -r requirements.txt
This workflow is the standard for Python projects across all platforms. It guarantees that everyone working on the project has identical library versions.
Setting the Default Python Version
FreeBSD doesn’t create a generic python3 symlink automatically because multiple versions can coexist. If you want python3 to point to your installed version, create the symlink manually:
ln -sf /usr/local/bin/python3.11 /usr/local/bin/python3
Verify the symlink works:
python3 --version
You should see the same version output:
Python 3.11.15
Do the same for pip if you want a generic pip3 command:
ln -sf /usr/local/bin/pip-3.11 /usr/local/bin/pip3
Be careful with this approach if you later install a different Python version. The symlinks won’t update automatically, so you’ll need to recreate them if you switch versions.
Conclusion
Python 3 and pip are straightforward to set up on FreeBSD 15 through the pkg package manager. The key takeaway: always use virtual environments for your projects rather than installing packages system-wide with pip. This keeps your base system clean and your project dependencies reproducible. For complete Python documentation and library references, check the official Python 3.11 docs.