
Introduction
Python is a modern high-level programming language for developing web applications, running artificial intelligence (AI) models, and performing data analysis. Pip, a standard package manager for Python, allows you to install and manage libraries or dependencies in your Python project.
This article explains how to install Pip on FreeBSD 14. You will also install multiple Python versions and create an isolated development environment using the venv module.
Prerequisites
Before you begin:
- Deploy a FreeBSD 14.0 instance on Vultr.
- Access the instance using SSH as a non-root user with sudo privileges.
- Update the instance.
Install Python
The FreeBSD operating system preinstalls Python by default, and you can also pull it from the package repositories using the pkg package manager. However, those Python versions might be out of date. Follow the steps below to verify the default Python version and install the latest Python version on your server by building the application from source.
View the default Python version.
console$ python --version
Output:
Python 3.11.9Download the latest Python version release file. For example, version
3.13. Visit the Python releases page to verify the latest version.console$ wget https://www.python.org/ftp/python/3.13.0/Python-3.13.0.tgz
Extract all files from the archive.
console$ tar -xvzf Python-3.13.0.tgz
Switch to the new Python directory. For example,
Python-3.13.0.console$ cd Python-3.13.0
Run the
configurescript to initialize the build process.console$ ./configure --with-system-ffi --with-computed-gotos --enable-shared
Use
maketo build Python from source.console$ make -j$(sysctl -n hw.ncpu)
Install Python. The
altinstalloption installs the Python version without overwriting the default version.console$ sudo make altinstall
View the new Python version.
console$ python3.13 --version
Output:
Python 3.13.0Verify that the default version is available and unchanged.
console$ python3 --version
Output:
Python 3.11.9You have installed the latest Python version on your FreeBSD server.
Run the following command to remove the pre-installed version.
console$ sudo rm /usr/local/bin/python3
Allow the
python3command to use the new version by default.console$ sudo ln -s /usr/local/bin/python3.13 /usr/local/bin/python3
Install PIP on FreeBSD 14
Pip is the standard Python package manager for installing and managing project dependencies. Depending on the running Python version, follow the steps below to verify and install Pip on FreeBSD 14 server.
View the default Pip version on your server.
console$ pip --version
Verify that the command fails with the following output:
-su: pip: not foundDownload the latest Pip installation script.
console$ wget https://bootstrap.pypa.io/get-pip.py
Install a Pip version based on your Python version, such as the Python 3.13 you installed earlier.
console$ sudo python3.13 get-pip.py
Output:
Collecting pip Using cached pip-24.2-py3-none-any.whl.metadata (3.6 kB) Using cached pip-24.2-py3-none-any.whl (1.8 MB) Installing collected packages: pip Attempting uninstall: pip Found existing installation: pip 24.2 Uninstalling pip-24.2: Successfully uninstalled pip-24.2 Successfully installed pip-24.2Install Pip using the default Python version on your server.
console$ sudo python3 get-pip.py
View the new Pip version.
console$ pip3.13 --version
Output:
pip 24.2 from /usr/local/lib/python3.13/site-packages/pip (python 3.13)Find out how to install pip on ubuntu to manage Python packages effectively in your development environment.
Test the Python Package
Follow the steps below to test the Python package on FreeBSD.
Access the Python shell.
console$ python3.13Run the following command to display a
Hello World, Greetings from Vultr!message in your terminal.python>>> print('Hello World, Greetings from Vultr!')
Output:
Hello World, Greetings from Vultr!Exit the Python shell.
python>>> quit()
Install a new Python module, such as
flaskusing Pip.console$ pip3.13 install flask
Output:
Collecting flask Downloading flask-3.0.3-py3-none-any.whl.metadata (3.2 kB) Collecting Werkzeug>=3.0.0 (from flask) Downloading werkzeug-3.0.4-py3-none-any.whl.metadata (3.7 kB) Collecting Jinja2>=3.1.2 (from flask) Downloading jinja2-3.1.4-py3-none-any.whl.metadata (2.6 kB) Collecting itsdangerous>=2.1.2 (from flask)
Install Multiple Python Versions
Multiple projects may require different Python versions on your server. You can install new Python versions using the pkg package manager or use a project management tool such as pyenv to install and manage multiple Python versions.
Update the server's package information index.
console$ sudo pkg update
Install the
gitdependency package.console$ sudo pkg install -y git
Install the
pyenvtool.console$ sudo pkg install -y pyenv
View the available Python versions you can install on your server.
console$ pyenv install --list
Output:
Available versions: 2.1.3 ......... 3.9.13 3.9.14 3.9.15 ......... 3.10.10 3.10.11 .......... 3.11.8 3.11.9 3.11.10 3.12.0 3.12-dev ......... 3.12.6 3.13.0rc2 3.13.0rc2t 3.13-dev 3.13t-dev 3.14-dev 3.14t-dev .........Install a specific Python version such as
3.14-dev.console$ pyenv install 3.14-dev
Install another version, such as
3.12.6.console$ pyenv install 3.12.6
View all installed Python versions in your environment.
console$ pyenv versions
Output:
* system (set by /home/user/.pyenv/version) 3.12.6 3.14-devSet a specific Python version as the default in your environment. For instance,
3.12.6.console$ pyenv global 3.12.6
View the active Python version in your environment.
console$ pyenv version
Output:
3.12.6 (set by /home/user/.pyenv/version)
Create a Python Virtual Environment
Python uses the venv module to create isolated virtual environments on your server, allowing you to separate specific dependencies in your project from the system-wide Python environment. Follow the steps below to create a new virtual environment using the venv module.
Create a new
myenvvirtual environment.console$ python3 -m venv myenv
Activate the
myenvvirtual environment.console$ . myenv/bin/activate
Verify that your terminal prompt changes and includes the name of the new environment similar to the output below.
console(myenv) user@vultr:~ $
View the active
pythonbinary path.console$ which python3
Verify that the Python binary is active in your virtual environment path similar to the output below.
/home/user/myenv/bin/python3Install a Python package such as
requestsusing Pip in the new environment.console$ pip install requests
Output:
Successfully installed certifi-2024.8.30 charset-normalizer-3.4.0 idna-3.10 requests-2.32.3 urllib3-2.2.3List all available Python modules in the environment.
console$ pip freeze
Output:
certifi==2024.8.30 charset-normalizer==3.4.0 idna==3.10 requests==2.32.3 urllib3==2.2.3Exit the virtual environment.
console$ deactivate
Conclusion
You have installed Pip on FreeBSD 14 along with Python. Additionally, you've installed multiple Python versions to use with different projects and packages on the server. Python supports various tools that can be integrated with other applications, such as database servers, to match your project needs. For further details, please visit the Python documentation.