Skip to content

Python Setup

Python

Python, created by Guido van Rossum in 1991, is a widely used programming language praised for its simplicity, readability, and versatility. Its clean syntax makes it easier to read and write code compared to languages like C, C++, or Rust.

There are many ways to install Python, and I recommend using the uv package manager for the best experience. Other options like conda, pyenv, or the official installers from Python.org are reliable and effective but may become limiting as your Python expertise grows.

Just know that uv will help you with tasks like:

  • Installing specific Python versions
  • Creating and managing virtual environments
  • Installing and managing Python packages and tools
  • Replacing several tools like conda, pyenv, pip, poetry, virtualenv, and more
  1. Install uv

    Terminal window
    brew install uv
  2. Update your shell PATH

    Terminal window
    uv tool update-shell
  3. Install Python

    Terminal window
    uv python install
Terminal window
uv run my_python_script.py
Terminal window
uv run python

IPython is a powerful interactive Python shell that provides a rich environment for data exploration, experimentation, and visualisation. It offers features like code completion, syntax highlighting, and the ability to execute code line by line. It is great for interactive learning and experimentation.

  1. Install IPython

    Terminal window
    uv tool install ipython --with pip
  2. Launch the IPython Interpreter

    Terminal window
    ipython

JupyterLab is a web application for creating interactive documents that combine code, text, equations, and rich visuals. It provides Python learners with an intuitive environment for coding and experimentation.

  1. Install JupyterLab

    Terminal window
    uv tool install jupyterlab
  2. Launch JupyterLab

    Terminal window
    jupyter-lab

Create a new Python project

Terminal window
uv init hello-world

Run the hello-world main.py example

Terminal window
uv run ./hello-world/main.py

uv will create the following files

  • Directoryhello-world
    • .git
    • Directory.venv
      • bin
      • lib
      • pyvenv.cfg
    • .gitignore
    • main.py
    • pyproject.toml
    • README.md
    • uv.lock

Create a virtual environment at .venv

Terminal window
uv venv

You can create a virtual environment with a specific Python version

Terminal window
uv venv --python 3.13

Activate the virtual environment

Terminal window
source .venv/bin/activate

Install a package in the virtual environment

Terminal window
uv pip install ...

List all installed packages in the virtual environment

Terminal window
uv pip list

Exit the virtual environment

Terminal window
deactivate