Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

ImportError: cannot import name BooleanTrue

Sage is complaining about not being able to import BooleanTrue from sympy.logic.boolalg. The error occurs when I try to plot a curve using a variable (please see below "plot(2*x)").

 $ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 8.6, Release Date: 2019-01-15                     │
│ Using Python 2.7.16. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
sage: plot(2*x)
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-cc8397b888b4> in <module>()
----> 1 plot(Integer(2)*x)

/usr/lib/python2.7/site-packages/sage/misc/decorators.pyc in wrapper(*args, **kwds)
    490                 options['__original_opts'] = kwds
    491             options.update(kwds)
--> 492             return func(*args, **options)
    493 
    494         #Add the options specified by @options to the signature of the wrapped

/usr/lib/python2.7/site-packages/sage/plot/plot.pyc in plot(funcs, *args, **kwds)
   1939 
   1940     if hasattr(funcs, 'plot'):
-> 1941         G = funcs.plot(*args, **original_opts)
   1942 
   1943         # If we have extra keywords already set, then update them

/usr/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.plot (build/cythonized/sage/symbolic/expression.cpp:62540)()
  12019                     param = A[0]
  12020                     try:
> 12021                         f = self._plot_fast_callable(param)
  12022                     except NotImplementedError:
  12023                         return self.function(param)

/usr/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._plot_fast_callable (build/cythonized/sage/symbolic/expression.cpp:62919)()
  12065         """
  12066         from sage.ext.fast_callable import fast_callable
> 12067         return fast_callable(self, vars=vars, expect_one_var=True)
  12068 
  12069     ############

/usr/lib/python2.7/site-packages/sage/ext/fast_callable.pyx in sage.ext.fast_callable.fast_callable (build/cythonized/sage/ext/fast_callable.c:4847)()
    493 
    494         etb = ExpressionTreeBuilder(vars=vars, domain=domain)
--> 495         et = x._fast_callable_(etb)
    496 
    497     if isinstance(domain, RealField_class):

/usr/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._fast_callable_ (build/cythonized/sage/symbolic/expression.cpp:61739)()
  11901             add(mul(ipow(v_0, 2), 2), v_1)
  11902         """
> 11903         from sage.symbolic.expression_conversions import fast_callable
  11904         return fast_callable(self, etb)
  11905 

/usr/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py in <module>()
    841 
    842 
--> 843 sympy_converter = SympyConverter()
    844 
    845 ##########

/usr/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py in __init__(self)
    686     def __init__(self):
    687         from sage.interfaces.sympy import sympy_init
--> 688         sympy_init()
    689 
    690     def pyobject(self, ex, obj):

/usr/lib/python2.7/site-packages/sage/repl/ipython_extension.pyc in wrapper(*args, **kwargs)
    560     def wrapper(*args, **kwargs):
    561         if not wrapper.has_run:
--> 562             result = func(*args, **kwargs)
    563             wrapper.has_run = True
    564             return result

/usr/lib/python2.7/site-packages/sage/interfaces/sympy.pyc in sympy_init()
    752     from sympy.functions.special.spherical_harmonics import Ynm
    753     from sympy.functions.special.tensor_functions import KroneckerDelta
--> 754     from sympy.logic.boolalg import BooleanTrue, BooleanFalse
    755     from sympy.integrals.integrals import Integral
    756     from sympy.polys.rootoftools import CRootOf

ImportError: cannot import name BooleanTrue

The error does not occur, when plot is used without a variable (like "plot(2)", the plot window pops up with a horizontal line).

$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 8.6, Release Date: 2019-01-15                     │
│ Using Python 2.7.16. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
sage: plot(2)
Launched png viewer for Graphics object consisting of 1 graphics primitive
sage:

I'm using Sage on Arch Linux (Manjaro):

$ uname -a
Linux gimbal 4.19.32-1-MANJARO #1 SMP PREEMPT Wed Mar 27 18:55:07 UTC 2019 x86_64 GNU/Linux

When I try to import BooleanTrue in the Python3 interactively, everything works like expected:

$ python3
Python 3.7.2 (default, Jan 10 2019, 23:51:51) 
[GCC 8.2.1 20181127] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sympy.logic.boolalg import BooleanTrue, BooleanFalse
>>> BooleanTrue
<class 'sympy.logic.boolalg.BooleanTrue'>
>>> BooleanFalse
<class 'sympy.logic.boolalg.BooleanFalse'>

However, in Python2 a similar error like in Sage occurs, and although I'm a Sage / Python newbie, I know that Sage uses Python2 AFAIK:

$ python2
Python 2.7.16 (default, Mar 11 2019, 18:59:25) 
[GCC 8.2.1 20181127] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sympy.logic.boolalg import BooleanTrue, BooleanFalse
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name BooleanTrue
>>>

Any ideas on how to solve or investigate this issue further would be appreciated!

ImportError: cannot import name BooleanTrue

Sage is complaining about not being able to import BooleanTrue from sympy.logic.boolalg. The error occurs when I try to plot a curve using a variable (please see below "plot(2*x)").

 $ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 8.6, Release Date: 2019-01-15                     │
│ Using Python 2.7.16. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
sage: plot(2*x)
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-cc8397b888b4> in <module>()
----> 1 plot(Integer(2)*x)

/usr/lib/python2.7/site-packages/sage/misc/decorators.pyc in wrapper(*args, **kwds)
    490                 options['__original_opts'] = kwds
    491             options.update(kwds)
--> 492             return func(*args, **options)
    493 
    494         #Add the options specified by @options to the signature of the wrapped

/usr/lib/python2.7/site-packages/sage/plot/plot.pyc in plot(funcs, *args, **kwds)
   1939 
   1940     if hasattr(funcs, 'plot'):
-> 1941         G = funcs.plot(*args, **original_opts)
   1942 
   1943         # If we have extra keywords already set, then update them

/usr/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.plot (build/cythonized/sage/symbolic/expression.cpp:62540)()
  12019                     param = A[0]
  12020                     try:
> 12021                         f = self._plot_fast_callable(param)
  12022                     except NotImplementedError:
  12023                         return self.function(param)

/usr/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._plot_fast_callable (build/cythonized/sage/symbolic/expression.cpp:62919)()
  12065         """
  12066         from sage.ext.fast_callable import fast_callable
> 12067         return fast_callable(self, vars=vars, expect_one_var=True)
  12068 
  12069     ############

/usr/lib/python2.7/site-packages/sage/ext/fast_callable.pyx in sage.ext.fast_callable.fast_callable (build/cythonized/sage/ext/fast_callable.c:4847)()
    493 
    494         etb = ExpressionTreeBuilder(vars=vars, domain=domain)
--> 495         et = x._fast_callable_(etb)
    496 
    497     if isinstance(domain, RealField_class):

/usr/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression._fast_callable_ (build/cythonized/sage/symbolic/expression.cpp:61739)()
  11901             add(mul(ipow(v_0, 2), 2), v_1)
  11902         """
> 11903         from sage.symbolic.expression_conversions import fast_callable
  11904         return fast_callable(self, etb)
  11905 

/usr/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py in <module>()
    841 
    842 
--> 843 sympy_converter = SympyConverter()
    844 
    845 ##########

/usr/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py in __init__(self)
    686     def __init__(self):
    687         from sage.interfaces.sympy import sympy_init
--> 688         sympy_init()
    689 
    690     def pyobject(self, ex, obj):

/usr/lib/python2.7/site-packages/sage/repl/ipython_extension.pyc in wrapper(*args, **kwargs)
    560     def wrapper(*args, **kwargs):
    561         if not wrapper.has_run:
--> 562             result = func(*args, **kwargs)
    563             wrapper.has_run = True
    564             return result

/usr/lib/python2.7/site-packages/sage/interfaces/sympy.pyc in sympy_init()
    752     from sympy.functions.special.spherical_harmonics import Ynm
    753     from sympy.functions.special.tensor_functions import KroneckerDelta
--> 754     from sympy.logic.boolalg import BooleanTrue, BooleanFalse
    755     from sympy.integrals.integrals import Integral
    756     from sympy.polys.rootoftools import CRootOf

ImportError: cannot import name BooleanTrue

The error does not occur, when plot is used without a variable (like "plot(2)", the plot window pops up with a horizontal line).line):

$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 8.6, Release Date: 2019-01-15                     │
│ Using Python 2.7.16. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
sage: plot(2)
Launched png viewer for Graphics object consisting of 1 graphics primitive
sage:

I'm using Sage on Arch Linux (Manjaro):

$ uname -a
Linux gimbal 4.19.32-1-MANJARO #1 SMP PREEMPT Wed Mar 27 18:55:07 UTC 2019 x86_64 GNU/Linux

When I try to import BooleanTrue in the Python3 interactively, everything works like expected:

$ python3
Python 3.7.2 (default, Jan 10 2019, 23:51:51) 
[GCC 8.2.1 20181127] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from sympy.logic.boolalg import BooleanTrue, BooleanFalse
>>> BooleanTrue
<class 'sympy.logic.boolalg.BooleanTrue'>
>>> BooleanFalse
<class 'sympy.logic.boolalg.BooleanFalse'>

However, in Python2 a similar error like in Sage occurs, and although I'm a Sage / Python newbie, I know that Sage uses Python2 AFAIK:

$ python2
Python 2.7.16 (default, Mar 11 2019, 18:59:25) 
[GCC 8.2.1 20181127] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from sympy.logic.boolalg import BooleanTrue, BooleanFalse
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name BooleanTrue
>>>

Any ideas on how to solve or investigate this issue further would be appreciated!