Problem running symbolic package v2.9.0 on MacOS (and other systems) with sympy v1.7.1

I’m a noob using Octave and struggled to install or use the “symbolic” package properly. Questions at the end of this message.
All instances of https:// replaced with h_____ to adhere to hyperlink restrictions for newbies posting; apologies :expressionless:

I'm using:

  • MacOS Big Sur v11.2.1
  • GNU Octave, v6.1.0 installed using HomeBrew
    .> Symbolic pkg v2.9.0
  • Python v3.9.1
    .> mpmath v1.2.1 installed using pip3
    .> sympy v1.7.1 installed using pip3

Dependencies for Symbolic pkg v2.9.0 @ Octave Forge - The 'symbolic' package are:

  • octave ≥ 4.2. OK!
    Runtime system dependencies
  • python, sympy (≥ 1.2) OK!
  • mpmath (≥ 1.0) OK!

SymPy supports according to Installation — SymPy 1.7.1 documentation
Only Python 3.5, 3.6, 3.7, and PyPy. (not OK?)
SymPy seems to be working in Python v3.9.1 as shown below.

I tested the sympy package at the Python prompt by doing the following

$ python
.>>> from sympy import *
.> x = Symbol('x')
.>>> limit(sin(x)/x, x, 0)
1
.>>> integrate(1/x, x)
log(x)

When I do the following in Octave

>> pkg load symbolic
>> syms a b c x
Symbolic pkg v2.9.0: Traceback (most recent call last):
  File "<stdin>", line 28, in <module>
AttributeError: '_PrintFunction' object has no attribute '__globals__'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 12, in octoutput_drv
  File "<stdin>", line 54, in octoutput
  File "<stdin>", line 55, in octoutput
AttributeError: module 'sympy' has no attribute 'compatibility'
Closing the Python communications link.

error: Python exception: AttributeError: '_PrintFunction' object has no attribute '__globals__'
    occurred in python_header import block.
    Try "sympref reset" and repeat your command?
    (consider filing an issue at h_____github.com/cbm755/octsympy/issues)
error: called from
    pycall_sympy__ at line 191 column 5
    valid_sym_assumptions at line 38 column 10
    assumptions at line 82 column 7
    syms at line 97 column 13

I tried sympref reset and repeated syms a b c x as suggested in the message above.
I did not log the problem at Issues · cbm755/octsympy · GitHub as was not sure what to report exactly.

I used the messages below reporting similar problems to base my questions on.

QUESTIONS I HAVE:

  1. Am I doing something wrong; overlooking something or missing something?
  2. Should I try downgrading my version of SymPy to 1.6 or even 1.5.1?
  3. Do these versions of SymPy work with Python 3.9 or should I downgrade my version of Python to ver 3.7 as well?
  4. How should I do these changes in order to make it all work correctly in Octave? It was already an adventure to get this far ;-).

All help is greatly appreciated.
Thanks in advance

AFAICT, you’ll need sympy 1.5.1 as of now:
symbolic not working with sympy 1.6 · Issue #1023 · cbm755/octsympy (github.com)

Will that work with Python 3.9?

Let me google that for you:
sympy 1.5.1 - Google Suche

Looks like it should.

My apologies for these inconveniences. Usually a first time user posting many many links is suspected to be a spam bot :sweat_smile: I increased the tolerance level from 2 to 10 links for a first time poster and reformatted your post that it is easier to read for users giving you help.

Thank you, much appreciated.!

Thanks very much for your help.

Just to reiterate for others that have a similar question.

  • Symbolic package v2.9.0 still require Sympy version v1.5.1.
  • Higher Sympy versions do still not work yet.
  • Sympy version up to 1.7.1 will work on Python 3.9 even though the Sympy website states it only has been tested up to Python 3.7.

Thanks to everybody to make software like this available.
Much appreciate all your efforts.

Even though the title includes MacOS, I don’t think the problem has anything to do with a Mac. I have Windows and had the “same problem” and the same fix in the sense of downgrading to v1.5.1.

My Anaconda environ had sympy at v 1.6.2. I did the recommended:

pip install --user sympy==1.5.1

at the Anaconda prompt, and that fixed my problem too. Then I had the happy result:

>> syms x
Symbolic pkg v2.9.0: Python communication link active, SymPy v1.5.1.
>> sympref display unicode
ans = (sym)
     ⎛x⎞
  sin⎜─⎟
     ⎝2⎠

Doing pip, I got this:

  WARNING: The script isympy.exe is installed in 'C:\Users\%username%\AppData\Roaming\Python\Python37\Scripts' which is not on PATH.
  Consider adding this directory to PATH

I ignored it. Anaconda recommends that it manage the paths.

Does anyone know if this is true for Windows too? I suspect it is. I have not gotten Octave symbolic to work since v 4.x and likely Py 2.7x. (My recall is sketchy.)

My present Anaconda environ has me at sympy v 1.6.2. I am thinking I need to down-rev too.

Greg

Sorry, I fixed the title. Yes, it is a general problem of the symbolic package not only for macOS.

Which version of Octave are you using and how did you install it?
Recent versions should be including the symbolic package in the Windows installer with a working version of sympy.

O v 6.2. I additionally tried installing symbolic-win-py-bundle-2.9.0.tar.gz

It turns out this issue has been known of for a bit of time. (This is not the only thread with this info.)

Installing that bundle might have broken the symbolic package that came with the Octave installer.

The symbolic package that is bundled in the Octave 6.2 installer for Windows works for me without installing anything else.

I started with the standard O v 6.2 installation and package load. It did not work for me, just as it did not for KriSoft. When the straightforward approach doesn’t work, we then try other approaches.

Sorry. I didn’t want to come across as criticizing. I’m just curious why it works here but not for you.
Did you use the installer or the zip file?

this is the first I really noticed that Octave >6.1 for windows started including the symbolic package. it hadn’t previously because it needed a python install. does this one include the bundle version to avoid that? (i don’t know the symbolic debug functions enough to find out myself)

I used the windows installer version.

@mmuetzel wants to point out, that if you have a fresh vanilla installation of Octave 6.2.0, you do not have to worry about installing the symbolic package. Everything is already available out of the box. Here a sample log of my MS Windows test system:

>> pkg load symbolic
>> sympref diagnose

Symbolic package diagnostics
============================

Python and SymPy are needed for most features of the Symbolic package.

The Python interpreter is currently: "python3".

Computers may have more than one Python interpreter installed.  If you
need to, you can select a different one using the PYTHON environment
variable (see "help sympref").  For example, to use Python 2, try
    setenv PYTHON python2
    sympref reset

Attempting to run python3 -c "print(\"Python says hello\")"

status = 0
output = Python says hello

Good, Python ran correctly.


Python version
--------------

Let's check what version of Python we are calling...

Attempting to run python3 -c "import sys; print(sys.version)"

status = 0
output = 3.8.2 (default, Apr 16 2020, 16:12:56)
[GCC 9.3.0]


SymPy Python Library
--------------------

SymPy is a Python library used by Symbolic for almost all features.

Attempting to run python3 -c "import sympy; print(sympy.__version__)"

status = 0
output = 1.4

SymPy must be at least version 1.2; you have version 1.4.

Good, a working version of SymPy is installed.


Python XML Parsing and DOM Support
----------------------------------

The XML DOM library is used by Symbolic for passing values to and from Python.

Some older versions of Python formatted XML output differently.  As long as yo
u
have any reasonably recent version of Python, this should pass.

Attempting to run python3 -c "import xml.dom.minidom as minidom; doc = minidom
.parseString(\"<item>value</item>\"); print(doc.toprettyxml(indent=\"\"))"

status = 0
output = <?xml version="1.0" ?>
<item>value</item>



Your kit looks good for running the Symbolic package.  Happy hacking!

>> syms x
Symbolic pkg v2.9.0: Python communication link active, SymPy v1.4.
>> factor(x^2-x-6)
ans = (sym) (x - 3)*(x + 2)

Yes, the standard Windows package installation did install the symbolic package. All I had to do is load it in the standard way. After that, I always got the same results with “sympref diagnose” that you have shown. Unfortunately, that good result of “diagnose” did not translate to functionality. (And I tried resets too.) Symbolic did not work. Rudimentary commands like “syms x” would fail. But when I downgraded to v1.5.1, it started to work. I wonder what would happen if I now upgraded…?

It used to get this before downgraded even though “diagnose” said things were fine:

    >> syms x
    Symbolic pkg v2.9.0: Waiting...............warning: readblock: timeout of 30 exceeded, breaking out
    warning: called from
        readblock at line 101 column 7
        python_ipc_popen2 at line 99 column 16
        python_ipc_driver at line 62 column 15
        pycall_sympy__ at line 163 column 11
        valid_sym_assumptions at line 38 column 10
        assumptions at line 82 column 7
        syms at line 97 column 13
    ```
    no output so far
    ```
    error: ipc_popen2: something wrong? timed out starting python
    error: called from
        python_ipc_popen2 at line 101 column 7
        python_ipc_driver at line 62 column 15
        pycall_sympy__ at line 163 column 11
        valid_sym_assumptions at line 38 column 10
        assumptions at line 82 column 7
        syms at line 97 column 13
    ```

Do you have any modifications to the default plain vanilla Octave 6.2.0 installation active? :sweat_smile: As you can see from my previous post, Octave 6.2.0 ships with bundled:

  • Python 3.8.2
  • SymPy 1.4
  • Symbolic pkg v2.9.0

Thus I cannot make any sense of it, when you are saying

Can you please specify what is running/modified on your system and what exact commands do not work alongside with the exact error message?

I think “does not depend on” also means “must not use.” IOW, even though we previously needed to ensure the “right” Python was pointed to, and the “right” version of SymPy was installed, we are required remove all prior references to those things. (I think this “complete packaging” and removal of other dependencies will make for a cleaner and more problem-free experience.)

The Octave 6.2 installation does not touch C:\Users\%username%\.octaverc. I rarely touch .octaverc, and when I do, it is typically to add/remove a search path, not review the entire file. That is where I put my “load” statements too. If there are references to Python in that startup file, then that will be what is used. Late yesterday, I commented out the line “setenv PYTHON C:\ProgramData\Anaconda3\pythonw” from .octaverc. If the two startup files “octaverc” are special, they will need to be checked too. (I don’t use those.) I reinstalled O v 6.2. (Package matgeom has some .m file that gets renamed on first O boot.)

It seems to work now, and is v1.4. There are some syntax warnings/problems in the diagnose report. These warnings did not exist with SymPy v1.5.1.

>> sympref diagnose

Symbolic package diagnostics
============================

Python and SymPy are needed for most features of the Symbolic package.

The Python interpreter is currently: "python3".

Computers may have more than one Python interpreter installed.  If you
need to, you can select a different one using the PYTHON environment
variable (see "help sympref").  For example, to use Python 2, try
    setenv PYTHON python2
    sympref reset

Attempting to run python3 -c "print(\"Python says hello\")"

status =                0
output = Python says hello

Good, Python ran correctly.

Python version
--------------

Let's check what version of Python we are calling...

Attempting to run python3 -c "import sys; print(sys.version)"

status =                0
output = 3.8.2 (default, Apr 16 2020, 16:12:56)
[GCC 9.3.0]


SymPy Python Library
--------------------

SymPy is a Python library used by Symbolic for almost all features.

Attempting to run python3 -c "import sympy; print(sympy.__version__)"

/usr/lib/python3.8/site-packages/mpmath/ctx_mp_python.py:892: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if other is 0:
/usr/lib/python3.8/site-packages/mpmath/ctx_mp_python.py:986: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if other is 0:
/usr/lib/python3.8/site-packages/sympy/solvers/diophantine.py:3186: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if feasible is 1:  # it's prime and k == 2
/usr/lib/python3.8/site-packages/sympy/plotting/plot.py:509: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if self.xscale is 'log':
/usr/lib/python3.8/site-packages/sympy/plotting/plot.py:529: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if self.xscale is 'log':
/usr/lib/python3.8/site-packages/sympy/plotting/plot.py:542: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if self.xscale is 'log':
/usr/lib/python3.8/site-packages/sympy/plotting/plot.py:549: SyntaxWarning: "is" with a literal. Did you mean "=="?
  if self.xscale is 'log':
status =                0
output = 1.4

SymPy must be at least version 1.2; you have version 1.4.

Good, a working version of SymPy is installed.

Python XML Parsing and DOM Support
----------------------------------

The XML DOM library is used by Symbolic for passing values to and from Python.
Some older versions of Python formatted XML output differently.  As long as you
have any reasonably recent version of Python, this should pass.

Attempting to run python3 -c "import xml.dom.minidom as minidom; doc = minidom.parseString(\"<item>value</item>\"); print(doc.toprettyxml(indent=\"\
"))"

status =                0
output = <?xml version="1.0" ?>
<item>value</item>



Your kit looks good for running the Symbolic package.  Happy hacking!

>> syms x
Symbolic pkg v2.9.0: Python communication link active, SymPy v1.4.
>> sin(x)/x
ans = (sym)
  sin(x)
  ------
    x
>>