Changing python interpreter used by octave is not working. always defaulting to distributed lib

  • How to replicate the Octave problem?
    1- open octave under windows ( 6.4.0 under windows 10 , see details below)
    2-set octave env variable of python to point to right interpreter.
    setenv PYTHON <userPath>\AppData\Local\Programs\Python\Python39\python.exe
    3-Check that it is set properly
    getenv("PYTHON")
    4- Type system("python")

Python 3.8.2 (default, Apr 16 2020, 16:12:56)
[GCC 9.3.0] on msys
Type “help”, “copyright”, “credits” or “license” for more information.

  • What did I expect to happen and what did happen?
    I expect octave to use the 3.9 python instead of 3.8. Also, if i try to run any python scripts using installed packages, they are not recognized ( matplotlib, tensorflow, etc…)
    Example :
>> python d:\CNN.py
Traceback (most recent call last):
  File "d:\CNN.py", line 2, in <module>
    from matplotlib import pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'

My system

The system function executes a command in the shell. If you’d like it to execute something that is stored in an environment variable, you could probably call something like this on Windows:

system('%PYTHON%')

i can’t remember when, but didn’t the windows build start including the ‘bundled python’ symbolic version? is that set up such that the package can only use the bundled version and ignores any system installed version? would uninstalling the pkg and reinstalling the standard, non-bundled package restore the intended behavior?

@nrjank: Uninstalling the Octave package symbolic won’t uninstall the bundled Python (nor would uninstalling any Octave package with pkg uninstall ... uninstall any other software than the package itself).
It also wouldn’t change the behavior here. Setting an environment variable (other than PATH) doesn’t change how executables are searched in the system PATH.

@Rik recently pushed a change to the default branch that will make the python function respect the PYTHON environment variable:
octave: 6cfc7af8eacc (gnu.org)

That’ll be part of Octave 8.1 when it is released probably early next year.
Until then, you could probably call python via system directly:

system('%PYTHON% d:\CNN.py');

On a system using the bundled version, uninstalling the symbolic package does indeed remove the bundled python, as it only exists as part of the package and in that case is not ‘any other software’. I had forgotten about Rik’s recent work there and thought perhaps something unique about the bundled package conflicted with other changes. (all that said, it appears that bundled version i was referring to stopped being supported with version 6 when it became part of the default build, so isn’t relevant anyway.)

This definitely worked. Thanks a lot for the hint.