Search code examples
pythonsympyoctave

Octave can't import sympy


I am on Mac M1 and I installed Octave with homebrew and need the Symbolic package. The Symbolic package depends on sympy.

I installed sympy with pipx and my .zshrc file is this:

export PATH="$PATH:/Users/(user)/.local/bin"
export PYTHONPATH="$PYTHONPATH:/Users/(user)/.local/pipx/venvs/sympy/lib/python3.13/site-packages"

When I type help("modules") on python3 in the terminal (/opt/homebrew/bin/python3), sympy appears.

But when I run Octave and type setenv PYTHON /opt/homebrew/bin/python3 and pkg load symbolic, the result of symspref diagnose is:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import sympy; print(sympy.__version__)
    ^^^^^^^^^^^^
ModuleNotFoundError: No module named 'sympy'
status = 1
output =

Solution

  • Found the answer:

    I added to /opt/homebrew/Cellar/octave/9.2.0_1/share/octave/site/m/startup/octaverc the lines:

    setenv("PYTHON", "/opt/homebrew/bin/python3")
    setenv("PYTHONPATH", [getenv("HOME")"/.local/pipx/venvs/sympy/lib/python3.13/site-packages"])