How to install Python in a clean and easy way
Install uv
Run the following
brew install uv
This will install uv and its dependencies.
info
uv is a fast project manager for Python.
Then run the following to install python 3.11.9
uv install 3.11.9
Then go to your working directory for your current project and run the following
uv init
This will create a new Python project with a pyproject.toml file
Then run the following to add any dependency to your project
uv add fastapi
When you run uv add to add dependencies, uv will create a virtual environment if it doesn't already exist. This virtual environment is typically created in a .venv directory in your project root.
Then run any script using uv
uv run main.py
This way you will have the benefits of avoiding conflicts between python package dependencies and using virtual environments without having to think about it.
Useful commands
add -- Add dependencies to the project
cache -- Manage uv's cache
clean -- Clear the cache, removing all entries or those linked to specific packages
generate-shell-completion -- Generate shell completion
help -- Display documentation for a command
init -- Create a new project
lock -- Update the project's lockfile
pip -- Manage Python packages with a pip-compatible interface
python -- Manage Python versions and installations
remove -- Remove dependencies from the project
run -- Run a command or script
sync -- Update the project's environment
tool -- Run and install commands provided by Python packages
tree -- Display the project's dependency tree
venv -- Create a virtual environment
version -- Display uv's version