Skip to content

Installation

This page demonstrate how to install Python and configure a Python development project.

Install Python

All instructions on this website assume using Fedora Linux. At time of writing that was Fedora 40 which shipped with Python 3.12.3.

However, it can be useful to install specific and multiple version f Python on you client.

Please refer to this appendix for installing Python from source.

Project Directory

First, create a suitable working directory for your project, for example:

mkdir -p ~/projects/example-for-you && cd ~/projects/example-for-you

Virtual Environment

Create a new Python Virtual Environment inside your project directory, for example using the default Python version:

python3 -m venv venv

Or being a little more specific if you want an alternative Python version:

python3.11 -m venv venv

Activate the Virtual Environment, and you’re all set:

source venv/bin/activate

The command source in the previous command can be substituted with a full stop, which is shorthand for source, for example you could use:

. venv/bin/activate

Now you are in an activate Python Virtual Environment, you can use the python command without any version number:

python -V

Typically, you will always need to upgrade pip within a new virtual environment:

pip install --upgrade pip

Python Requirements

As you work through any Python project, you'll probably encounter numerous requirements. Python packages are installed using pip, and packages can be browsed at https://pypi.org/. This is a FastAPI project, therefore we’ll need to install the fastapi package, and additionally a server to run our application. In this case we’ll be using uvicorn.

Install these packages:

pip install fastapi uvicorn[standard]

I like to maintain a non-versioned requirements file in addition to a frozen requirements file. Create a new text file in the root of your project directory called non_ver_reqs.txt containing the two packages:

non_ver_reqs.txt
fastapi
uvicorn[standard]

Using a non-versioned requirements file is good for keeping track of the high-level packages you install for a project. In addition, it makes life easier when installing them using different versions of Python 3, for example if you upgraded from Python3.9 to Python3.11.

Packages are installed using these files with the -r argument, for example:

pip install -r non_ver_reqs.txt

Tip

It's important to know that using non_ver_reqs.txt is risky in the sense new packages can break your code. For example, a new major version of a dependant package such as Pydantic which FastAPI is built upon, can break compatibility. Therefore, it's important to use pip freeze to ensure you projects can work as-is, and use non_ver_reqs.txt to get everything at the latest version fixing projects forwards.

Additionally, use pip freeze to lock in the versioning of installed packages. This command also includes any dependency packages, and is typically used in production for ensuring Python applications are deployed to specific versions.

pip freeze > requirements.txt

As you work through any project you’ll repeat these steps when new Python packages are included in your project.