Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

ImportError when using find_root

Any time I try to use find_root, whether in the notebook or the interpreter, it gives me an import error complaining that it can't find libgfortran

This has persisted after re-installing

I installed sage through the MacOS dmg, it is running the arm64 version on an M1, and the version of sage is 9.7

Does anyone know why this might be happening?

It gives this specific error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 find_root(x**Integer(2)==Integer(2),Integer(1),Integer(3))

File /private/var/tmp/sage-9.7-current/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/sage/misc/lazy_import.pyx:391, in sage.misc.lazy_import.LazyImport.__call__ (build/cythonized/sage/misc/lazy_import.c:4397)()
389         True
390     """
--> 391     return self.get_object()(*args, **kwds)
392 
393 def __repr__(self):

File /private/var/tmp/sage-9.7-current/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/sage/numerical/optimize.py:106, in find_root(f, a, b, xtol, rtol, maxiter, full_output)
 20 r"""
 21 Numerically find a root of ``f`` on the closed interval `[a,b]`
 22 (or `[b,a]`) if possible, where ``f`` is a function in the one variable.
   (...)
103 
104 """
105 try:
--> 106     return f.find_root(a=a,b=b,xtol=xtol,rtol=rtol,maxiter=maxiter,full_output=full_output)
107 except AttributeError:
108     pass

File /private/var/tmp/sage-9.7-current/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/sage/symbolic/expression.pyx:12596, in sage.symbolic.expression.Expression.find_root (build/cythonized/sage/symbolic/expression.cpp:93733)()
  12594 f = self._plot_fast_callable(self.default_variable())
  12595 ff = FastCallableFloatWrapper(f, imag_tol=imaginary_tolerance)
> 12596 return find_root(ff, a=a, b=b, xtol=xtol,
  12597                  rtol=rtol,maxiter=maxiter,
12598                  full_output=full_output)

File /private/var/tmp/sage-9.7-current/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/sage/numerical/optimize.py:157, in find_root(f, a, b, xtol, rtol, maxiter, full_output)
154     a = min(s_1, s_2)
155     b = max(s_1, s_2)
--> 157 import scipy.optimize
158 brentqRes = scipy.optimize.brentq(f, a, b,
159                              full_output=full_output, xtol=xtol, rtol=rtol, maxiter=maxiter)
160 # A check following :trac:`4942`, to ensure we actually found a root
161 # Maybe should use a different tolerance here?
162 # The idea is to take roughly the derivative and multiply by estimated
163 # value of the root

File /private/var/tmp/sage-9.7-current/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/scipy/optimize/__init__.py:399, in <module>
  1 """
  2 =====================================================
  3 Optimization and root finding (:mod:`scipy.optimize`)
   (...)
396 
397 """
--> 399 from ._optimize import *
400 from ._minimize import *
401 from ._root import *

File /private/var/tmp/sage-9.7-current/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/scipy/optimize/_optimize.py:34, in <module>
 32 import numpy as np
 33 from scipy.sparse.linalg import LinearOperator
---> 34 from ._linesearch import (line_search_wolfe1, line_search_wolfe2,
 35                           line_search_wolfe2 as line_search,
 36                           LineSearchWarning)
 37 from ._numdiff import approx_derivative
 38 from ._hessian_update_strategy import HessianUpdateStrategy

File /private/var/tmp/sage-9.7-current/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/scipy/optimize/_linesearch.py:16, in <module>
  1 """
  2 Functions
  3 ---------
   (...)
 12 
 13 """
 14 from warnings import warn
---> 16 from scipy.optimize import _minpack2 as minpack2
 17 import numpy as np
 19 __all__ = ['LineSearchWarning', 'line_search_wolfe1', 'line_search_wolfe2',
 20            'scalar_search_wolfe1', 'scalar_search_wolfe2',
 21            'line_search_armijo']

ImportError: dlopen(/private/var/tmp/sage-9.7-current/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/scipy/optimize/_minpack2.cpython-310-darwin.so, 0x0002): Library not loaded: '@rpath/libgfortran.5.dylib'
  Referenced from: '/Applications/SageMath-9-7.app/Contents/Frameworks/Sage.framework/Versions/9.7/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/scipy/optimize/_minpack2.cpython-310-darwin.so'
  Reason: tried: '/Applications/SageMath-9-7.app/Contents/Frameworks/Sage.framework/Versions/9.7/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/scipy/optimize/libgfortran.5.dylib' (no such file), '/Applications/SageMath-9-7.app/Contents/Frameworks/Sage.framework/Versions/9.7/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/scipy/optimize/libgfortran.5.dylib' (no such file), '/Applications/SageMath-9-7.app/Contents/Frameworks/Sage.framework/Versions/9.7/local/var/lib/sage/venv-python3.10.5/bin/../lib/libgfortran.5.dylib' (no such file), '/usr/local/lib/libgfortran.5.dylib' (no such file), '/usr/lib/libgfortran.5.dylib' (no such file)
click to hide/show revision 2
retagged

ImportError when using find_root

Any time I try to use find_root, whether in the notebook or the interpreter, it gives me an import error complaining that it can't find libgfortran

This has persisted after re-installing

I installed sage through the MacOS dmg, it is running the arm64 version on an M1, and the version of sage is 9.7

Does anyone know why this might be happening?

It gives this specific error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 find_root(x**Integer(2)==Integer(2),Integer(1),Integer(3))

File /private/var/tmp/sage-9.7-current/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/sage/misc/lazy_import.pyx:391, in sage.misc.lazy_import.LazyImport.__call__ (build/cythonized/sage/misc/lazy_import.c:4397)()
389         True
390     """
--> 391     return self.get_object()(*args, **kwds)
392 
393 def __repr__(self):

File /private/var/tmp/sage-9.7-current/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/sage/numerical/optimize.py:106, in find_root(f, a, b, xtol, rtol, maxiter, full_output)
 20 r"""
 21 Numerically find a root of ``f`` on the closed interval `[a,b]`
 22 (or `[b,a]`) if possible, where ``f`` is a function in the one variable.
   (...)
103 
104 """
105 try:
--> 106     return f.find_root(a=a,b=b,xtol=xtol,rtol=rtol,maxiter=maxiter,full_output=full_output)
107 except AttributeError:
108     pass

File /private/var/tmp/sage-9.7-current/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/sage/symbolic/expression.pyx:12596, in sage.symbolic.expression.Expression.find_root (build/cythonized/sage/symbolic/expression.cpp:93733)()
  12594 f = self._plot_fast_callable(self.default_variable())
  12595 ff = FastCallableFloatWrapper(f, imag_tol=imaginary_tolerance)
> 12596 return find_root(ff, a=a, b=b, xtol=xtol,
  12597                  rtol=rtol,maxiter=maxiter,
12598                  full_output=full_output)

File /private/var/tmp/sage-9.7-current/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/sage/numerical/optimize.py:157, in find_root(f, a, b, xtol, rtol, maxiter, full_output)
154     a = min(s_1, s_2)
155     b = max(s_1, s_2)
--> 157 import scipy.optimize
158 brentqRes = scipy.optimize.brentq(f, a, b,
159                              full_output=full_output, xtol=xtol, rtol=rtol, maxiter=maxiter)
160 # A check following :trac:`4942`, to ensure we actually found a root
161 # Maybe should use a different tolerance here?
162 # The idea is to take roughly the derivative and multiply by estimated
163 # value of the root

File /private/var/tmp/sage-9.7-current/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/scipy/optimize/__init__.py:399, in <module>
  1 """
  2 =====================================================
  3 Optimization and root finding (:mod:`scipy.optimize`)
   (...)
396 
397 """
--> 399 from ._optimize import *
400 from ._minimize import *
401 from ._root import *

File /private/var/tmp/sage-9.7-current/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/scipy/optimize/_optimize.py:34, in <module>
 32 import numpy as np
 33 from scipy.sparse.linalg import LinearOperator
---> 34 from ._linesearch import (line_search_wolfe1, line_search_wolfe2,
 35                           line_search_wolfe2 as line_search,
 36                           LineSearchWarning)
 37 from ._numdiff import approx_derivative
 38 from ._hessian_update_strategy import HessianUpdateStrategy

File /private/var/tmp/sage-9.7-current/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/scipy/optimize/_linesearch.py:16, in <module>
  1 """
  2 Functions
  3 ---------
   (...)
 12 
 13 """
 14 from warnings import warn
---> 16 from scipy.optimize import _minpack2 as minpack2
 17 import numpy as np
 19 __all__ = ['LineSearchWarning', 'line_search_wolfe1', 'line_search_wolfe2',
 20            'scalar_search_wolfe1', 'scalar_search_wolfe2',
 21            'line_search_armijo']

ImportError: dlopen(/private/var/tmp/sage-9.7-current/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/scipy/optimize/_minpack2.cpython-310-darwin.so, 0x0002): Library not loaded: '@rpath/libgfortran.5.dylib'
  Referenced from: '/Applications/SageMath-9-7.app/Contents/Frameworks/Sage.framework/Versions/9.7/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/scipy/optimize/_minpack2.cpython-310-darwin.so'
  Reason: tried: '/Applications/SageMath-9-7.app/Contents/Frameworks/Sage.framework/Versions/9.7/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/scipy/optimize/libgfortran.5.dylib' (no such file), '/Applications/SageMath-9-7.app/Contents/Frameworks/Sage.framework/Versions/9.7/local/var/lib/sage/venv-python3.10.5/lib/python3.10/site-packages/scipy/optimize/libgfortran.5.dylib' (no such file), '/Applications/SageMath-9-7.app/Contents/Frameworks/Sage.framework/Versions/9.7/local/var/lib/sage/venv-python3.10.5/bin/../lib/libgfortran.5.dylib' (no such file), '/usr/local/lib/libgfortran.5.dylib' (no such file), '/usr/lib/libgfortran.5.dylib' (no such file)