python on Windows

Took another stab at this, esp. for a corp. environ., where SSL certificate checks break due to the deployed packet inspection monitoring software (man-in-the-middle). There’s now a short guide in pdf at my repo. python-setup.


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 --system-certs
    
  3. Initialise project folder and install modules2 required by the project

     uv init
     uv add numpy matplotlib pandas --system-certs
    

    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\\%USERNAME%\\.local\\bin;$path",
         "working_dir" : "$file_path"
     }
    

    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 Ctrl B 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.

  2. In places where a man-in-the-middle monitor (like in a corp. environ.) breaks the trust causing SSL failures, one may resort to using --system-certs switch to overcome this nuisance.