python on Windows
Beginners can’t go wrong with Thonny (portable) and can ignore the following — meant for those familiar with CLI and the concept of virtual environs.
Setting python up on Windows 11 is needlessly complex, but it does not have to be, Microsoft’s own guide notwithstanding.1 For its part, python has been a victim of its own success. The best way to overcome system-wide conflicts and other teething issues is by setting-up and managing project-specific versions and modules via virtual environments. The absolute best tool for this job is uv from the boutique start-up, Astral. It gets you off the ground like nothing ever has before. Here’s how.
-
Install uv
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"Restart PowerShell for the path to uv to reload and be accessible from the command line.
-
Install python
uv python install -
Initialise project folder and install modules required by the project
uv init uv add numpy matplotlib pandasuv project manages python version and the packages required for the project.
-
Run a script
uv run somescript.pyPython via uv is now setup to run scripts from command line. (See also some helpful guides.)
-
Set it up to run from within a text editor, say, Sublime Text
From Tools > Build System, choose New Build System.., and in the opened tab/window, paste the following:
{ "shell_cmd" : "uv run \"$file_name\"", "selector" : "source.python", "path" : "C\\Users\\ckun\\.local\\bin;$path", "working_dir" : "$file_path" }Be sure to change the
pathin the above to reflect your own Windows username in lieu ofckun. Save the file asPython-uv.sublime-build. Now with a python script in the editor, select Python-uv from Tools > Build System, and hit CtrlB to run the script.
And for every new project, you will have to use steps 3 and 4 from above, i.e., (a) initialise, (b) add the required modules, and (c) run.
-
The wheels come off when you try setting-up Visual Studio Code editor along with it, especially when making it play nice with uv and installing modules. ↩