python on Windows

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.

  1. 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.

  2. Install python

    uv python install
    
  3. Initialise project folder and install modules required by the project

    uv init
    uv add numpy matplotlib pandas
    

    uv project manages python version and the packages required for the project.

  4. Run a script

    uv run somescript.py
    

    Python via uv is now setup to run scripts from command line. (See also some helpful guides.)

  5. 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 path in the above to reflect your own Windows username in lieu of ckun. Save the file as Python-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.


  1. 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.