Tools
The UV
package (Link)
UV
is a Python package management system that replaces pip
, pip-tools
, pipx
, poetry
, pyenv
, twine
, virtualenv
, and more, and is said to be 10-100x faster than pip
.
# On macOS and Linux.
curl -LsSf https://astral.sh/uv/install.sh | sh
Alternatively, you can use homebrew to install uv
brew install uv
If installed via the standalone installer, uv
can update itself to the latest version:
uv self update
Usage
# Insatall a specific version of Python
uv python install 3.12
# Create a new Python project
uv init
# Add a dependency to the project
uv add python-dotenv
# Remove a dependency from the project
uv remove python-dotenv
# Sync the project's dependencies with the environment
uv sync
uv
supports virtual environments, e.g., to create a virtual environment at .venv
:
uv venv
# Activate with: source .venv/bin/activate
source .venv/bin/activate
# Deactivate
deactivate
Environment inspection
List globally installed packages.
pip list
pip freeze
To visualise the package dependencies, use pipdeptree
.
# Install pipdeptree
pip install pipdeptree
# Visualise the dependency tree
pipdeptree
Setting up .venv
It is recommended that a virtual environment be created for your project.
# Use any virtual environment
PROJECT_NAME=colab-notebooks
python3 -m venv ~/Workspace/${PROJECT_NAME}/.venv
source ~/Workspace/${PROJECT_NAME}/.venv/bin/activate
Load environment variables via python-dotenv
dotenv.load_dotenv()
Install packages listed in the requirements.txt
pip install -r /path/to/requirements.txt
Creating requirements.txt
Create a requirements.txt
fire from within an existing project:
pip freeze > requirements.txt
IDE setup for Python.
Install Python LSP server (Emacs)
This is required for the lsp-mode
in Emacs.
pip install "python-lsp-server[all]"
Run Jupyter Notebooks with VS Code
-
Install
Jupyter
extension for VS Code. -
Create a virtual environment in the project directory.
# Use any virtual environment
python3 -m venv ~/Workspace/project_name/.venv
source ~/Workspace/project_name/.venv/bin/activate
- In VS Code, press
Cmd+Shift+P
, selectPython: Select Interpreter
and choose the virtual env you just created.