1 Getting Started
1.1 Introduction
For historical and technical reasons installing Python and managing dependencies is more cumbersome than it should be and as of today (October 2024) there are way too many ways to deal with those problems. My recommendation here is: Pick one system that works for you and stick to it.
We essentially need to carry out three tasks:
- Install Python (the language itself)
- Manage virtual environments
- Install third party libraries
We will use here uv
which is a high level tool that does all three for us.
1.2 Install uv
Run only one of these commands in your terminal - pick according to your operating system:
Linux and macOS
curl -LsSf https://astral.sh/uv/install.sh | sh
Windows
Make sure you are using powershell!
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
That should be enough, but for more details you can follow detailed instructions here.
1.3 Working on a project
To start a new project run in your terminal:
uv init pycourse --lib --python 3.12
pycourse
is the name of the project, you can choose anything you want.
The --lib
flag tells uv
to install the current code as a “library” (don’t worry about this yet, it’s just something we need to get things working for now).
The --python
flags specifies the specific python version we want to work with in this project. If the version is already installed in our machine uv
will just use it, otherwise uv
will download it and keep it for future usage.
uv
will create a new directory with all the necessary boilerplate to get python running, including a virtual environment (by default, under the hidden directory .venv
) and a pyproject.toml
file (we’ll look at those later when dealing with dependencies).
For more details on uv
and projects see the documentation here.
Change your directory into the newly created folder:
cd pycourse
You should see a structure like this:
pycourse
├── pyproject.toml
├── README.md
└── src
└── pycourse
└── __init__.py
If everything worked fine you should be able to run this:
uv run python
and see a python REPL.
We’re ready to go 🚀!