Python Setup
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.
Considerations
Section titled “Considerations”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
Installing Python with uv
Section titled “Installing Python with uv”-
Install
uv
Terminal window brew install uv -
Update your shell PATH
Terminal window uv tool update-shell -
Install Python
Terminal window uv python install
Running Python Code
Section titled “Running Python Code”uv run my_python_script.py
Launching the Python Interpreter
Section titled “Launching the Python Interpreter”uv run python
Launching the IPython Interpreter
Section titled “Launching the IPython Interpreter”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.
-
Install IPython
Terminal window uv tool install ipython --with pip -
Launch the IPython Interpreter
Terminal window ipython
Launching the JupyterLab
Section titled “Launching the JupyterLab”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.
-
Install JupyterLab
Terminal window uv tool install jupyterlab -
Launch JupyterLab
Terminal window jupyter-lab
Working on projects
Section titled “Working on projects”Create a new Python project
uv init hello-world
Run the hello-world main.py
example
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
Using Python environments
Section titled “Using Python environments”Create a virtual environment at .venv
uv venv
You can create a virtual environment with a specific Python version
uv venv --python 3.13
Activate the virtual environment
source .venv/bin/activate
Install a package in the virtual environment
uv pip install ...
List all installed packages in the virtual environment
uv pip list
Exit the virtual environment
deactivate