Ask Your Question
0

ImportError: cannot import name BooleanTrue [closed]

asked 2019-03-31 17:04:01 +0100

rel gravatar image

updated 2019-03-31 17:04:45 +0100

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!

edit retag flag offensive reopen merge delete

Closed for the following reason too localized by Iguananaut
close date 2019-04-03 12:47:26.164850

2 Answers

Sort by » oldest newest most voted
0

answered 2019-04-01 15:46:24 +0100

rel gravatar image

Ok, I've found a solution, but I have no idea where that problematic sympy-0.7.3-py2.7.egg package came from:

$ 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.
>>> import os.path
>>> import sympy
>>> print(os.path.abspath(sympy.__file__))
/usr/lib/python2.7/site-packages/sympy-0.7.3-py2.7.egg/sympy/__init__.pyc
>>> 

$ pacman -Qo /usr/lib/python2.7/site-packages/sympy-0.7.3-py2.7.egg/sympy/__init__.pyc
error: No package owns /usr/lib/python2.7/site-packages/sympy-0.7.3-py2.7.egg/sympy/__init__.pyc

$ sudo mv /usr/lib/python2.7/site-packages/sympy-0.7.3-py2.7.egg/ ~/tmp

$ 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.
>>> import sympy
>>> from sympy.logic.boolalg import BooleanTrue, BooleanFalse
>>> BooleanTrue
<class 'sympy.logic.boolalg.BooleanTrue'>
>>>
edit flag offensive delete link more
1

answered 2019-03-31 19:31:14 +0100

Emmanuel Charpentier gravatar image

WorksForMe(TM) in sage 8.8.beta0 (manuel install).

Could you try Sage 8.7

edit flag offensive delete link more

Comments

Thanks for the hint! - The strange thing is, that the error only shows up on my laptop, which is using the same OS as my desktop machine, where Jupyter Notebook with Sage 8.6 works perfectly fine.

I'm going to try to install sagemath-git 8.8.beta0.r0.g44abe7e009-1 on the Laptop, to check if that remedies the problem.

rel gravatar imagerel ( 2019-03-31 21:27:51 +0100 )edit

Well, building Sage from the source isn't an option on my laptop, it's simply too big and stalls the machine...

But I think the problem is not directly related to Sage after all, since I found out that Python2 is normally able to import that Boolean stuff from sympy, when everything is installed correctly. - I've tested it on my other Arch Linux machine:

$ 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
>>> BooleanFalse
<class 'sympy.logic.boolalg.BooleanFalse'>
rel gravatar imagerel ( 2019-04-01 12:23:02 +0100 )edit

Question Tools

1 follower

Stats

Asked: 2019-03-31 17:04:01 +0100

Seen: 582 times

Last updated: Apr 01 '19