WINDOWS: Python Setup on Windows (using scoop)
Introduction
Dealing with different versions of Python and tools might be trickier on Windows than Linux due to the way packages work on Windows.
This post describes an easy way similar to Linux or MacOS to manage Python and Python Versions using scoop.
Requirements
Install scoop.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
Install Python
You can easily install the latest stable python release by running
scoop install main/python
Install Python Version
If you would like to install different python versions, is really easy to deal with it using scoop
Install the versions you required, for example from the following list
scoop install versions/python27
scoop install versions/python35
scoop install versions/python37
scoop install versions/python38
scoop install versions/python39
scoop install versions/python310
scoop install versions/python311
scoop install versions/python312
To have them available on your path then just use scoop for it
scoop reset python35
python --version
# Python 3.5
scoop reset python 39
python --version
# Python 3.9.13
Extra tools
Pipx - Package manager
pipx — Install and Run Python Applications in Isolated Environments. Similar to scoop, brew or apt is a package manager but for Python apps.
Install pipx with scoop by running
scoop install main/pipx
Then you can install with pipx applications that are written in python. For example, pre-commit
pipx insall pre-commit
WARNING
Combining pipx with scoop is fine, but you might end up having issues with pipx underlying python version when updating it via scoop.
It is recommended to hold pipx and upgrade only when necessary:
scoop hold pipx
Poetry
Poetry is a tool that serves as an alternative to the standards build-tools and pip.
It helps you manage python versions, environments, dependencies in a fluent and easy way.
Install it by running
scoop install main/poetry
ruff
ruff is the fastest linter and code formatter. It is usually not necessary to be installed as should run as part of your dev workflow, for example using git hooks.
If you prefer to run it manually, you can also install it
scoop install main/ruff
Then you can run
ruff check # Lint all files in the current directory.
ruff format # Format all files in the current directory.
uv and uvx
TIP
Prefer uvx (uv tool) over pipx
uv is an extremely fast Python package and project manager, written in Rust.
scoop install main/uv
Although it can be used for the same purpose of poetry, also it comes with uvx which serves the same purpose as pipx but faster.
For example, to run a hello world
uvx pycowsay 'hello world!'
VSCode editor
It is highly recommended to use vscode for your dev environment.
In order to have a good setup, you will need to install the following extensions: