Last active
September 2, 2023 04:16
Star
You must be signed in to star a gist
Find all installed Python packages from the Microsoft store, determine install location, and register them as external evalautors.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Run this every time the Python from the Store updates, since the binary location encodes the store full version *) | |
(* Note that Python 3.9 is supported in Mathematica 12.3.1, so the below patches are not relevant on modern versions, but are retained to aid those running older versions from perpetual licenses *) | |
(* Update to support Mathematica 12, which requires that Python >=3.8 at least reference python3.8.exe, not python.exe. *) | |
(* Note, python >3.7 is not officially supported in Mathematica 12.0.0, and other notebook interfaces. | |
Attempts to use it result in a "required field 'type_ignores' missing from module" error | |
Source: https://mathematica.stackexchange.com/questions/211984/solved-externalevaluatepysys-pycmd-evaluates-to-failure *) | |
(* | |
A patch to C:\Program Files\Wolfram Research\Mathematica\12.0\SystemFiles\Links\WolframClientForPython\wolframclient\utils\externalevaluate.py to enable 3.8: | |
66c66 | |
< exec(compile(ast.Module(expressions, []), '', 'exec'), current) | |
--- | |
> exec(compile(ast.Module(expressions), '', 'exec'), current) | |
*) | |
RegisterExternalEvaluator["Python", | |
StringTrim[#] <> | |
StringCases[#, {___ ~~ "PythonSoftwareFoundation.Python." ~~ M_ ~~ | |
"." ~~ m : RegularExpression["[^_]*"] -> {"\\python", M, ".", | |
m, ".exe"}}]] & /@ | |
StringSplit[ | |
RunProcess[{"powershell.exe", | |
"(Get-AppxPackage | where {$_.name -match \ | |
'PythonSoftwareFoundation.Python.[23]'}).InstallLocation"}, | |
"StandardOutput"], "\n"] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to support Python 3.10+, as the script assumed the minor version was a single character.
You can find the list of ExternalEvaluators at
%APPDATA%\Roaming\Wolfram\Objects\Persistence\ExternalEvaluate%60EvaluatorCache%60Python\put.wl
and you can delete that file before running this to remove the old one.