Upgrading Python 2.7.16 libraries on MacOS Big Sur 11.3

655 Views Asked by At

To confirm results of a colleague who has coded an interpolation with Cubicspline from scipy with python2 , I have to import CubicSpline function. I know python2 is deprecated but this is just for a validation.

But when i do a :

from scipy.interpolate import CubicSpline

I have systematically the error message :

ImportError: cannot import name CubicSpline

So, I tried to install it with pip-2.7 by doing :

curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py

python2.7 get-pip.py

and after from the directory ~/Library/Python/2.7/bin :

./pip2.7 install scipy

but same error, CubicSpline is not found

I have the version :

$ which python2.7
/usr/bin/python2.7

So python2.7 is the default python2 of the system.

How to install CubicSpline library on the default installation of python2.7 in the OS ?

Have I got to reinstall all the python2.7 framework ? and if yes, how to perform it ?

Update 1

The situation has become worse :

After doing $ python2.7 -m pip install scipy numpy I get now :

$ python2.7
Python 2.7.16 (v2.7.16:413a49145e, Mar  2 2019, 14:32:10)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(.startup.py)
Traceback (most recent call last):
  File "/Users/fab/.startup.py", line 3, in <module>
    import numpy as np
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/__init__.py", line 142, in <module>
    from . import core
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/__init__.py", line 71, in <module>
    raise ImportError(msg)
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the multiarray numpy extension module failed.  Most
likely you are trying to import a failed build of numpy.
Here is how to proceed:
- If you're working with a numpy git repository, try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.
- If you are simply trying to use the numpy version that you have installed:
  your installation is broken - please reinstall numpy.
- If you have already reinstalled and that did not fix the problem, then:
  1. Check that you are using the Python you expect (you're using /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python),
     and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy versions you're trying to use.
  2. If (1) looks fine, you can open a new issue at
     https://github.com/numpy/numpy/issues.  Please include details on:
     - how you installed Python
     - how you installed numpy
     - your operating system
     - whether or not you have multiple versions of Python installed
     - if you built from source, your compiler versions and ideally a build log

     Note: this error has many possible causes, so please don't comment on
     an existing issue about this - open a new one instead.

Original error was: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/_multiarray_umath.so, 2): Symbol not found: ___addtf3
  Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/../.dylibs/libquadmath.0.dylib
  Expected in: /usr/lib/libSystem.B.dylib
 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/../.dylibs/libquadmath.0.dylib

Finally, I decided to use Macport, but there is yet a problem when I do :

$ /opt/local/bin/python2.7

Original error was: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/_multiarray_umath.so, 2): Symbol not found: ___addtf3
  Referenced from: /opt/local/lib/libgcc/libquadmath.0.dylib
  Expected in: /usr/lib/libSystem.B.dylib
 in /opt/local/lib/libgcc/libquadmath.0.dylib

On Big Sur, I saw that file libSystem.B.dylib didn't exist anymore.

How to circumvent all these issues ?

Update 2

Things are better but not all is done.

I removed python2.7 from MacPorts and useless binaries of kind python2* located into /usr/local/bin/.

Now, I have only the binary python2.7 coming from /usr/bin/python2.7 :

WARNING: Python 2.7 is not recommended.
This version is included in macOS for compatibility with legacy software.
Future versions of macOS will not include Python 2.7.
Instead, it is recommended that you transition to using 'python3' from within Terminal.

Python 2.7.16 (default, Feb 28 2021, 12:34:25)
[GCC Apple LLVM 12.0.5 (clang-1205.0.19.59.6) [+internal-os, ptrauth-isa=deploy on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import scipy
>>> from scipy.interpolate import CubicSpline
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name CubicSpline
>>>

As you can see, numpy and scipy are well loaded but there is still this problem with this line : from scipy.interpolate import CubicSpline

I would like to know where is located this library CubicSpline. Indeed, Recently, I could make run a "python2.7" code version and there were no problems for the loading and using of this function CubicSpline.

Where are stored numpy and scipy for the OS System version of python2.7

Update 3

I have finally found where the issue comes from. CubicSpline seems to be only available for scipy > 0.18. But on my MacBook, if I do :

$ import scipy
  scipy.version.version

I get :

>>> scipy.version.version
            '0.13.0b1'

Is there a way to upgrade the scipy of MacOS Big Sur Python 2.7 default system (I mean without using Brew/Macports) ?

Update 4

I don't understand anything, on a similar MacBook Pro with Big Sur 11.3, if I do :

/usr/bin/python2.7

I get :

Python 2.7.16 (default, Feb 28 2021, 12:34:25)
[GCC Apple LLVM 12.0.5 (clang-1205.0.19.59.6) [+internal-os, ptrauth-isa=deploy on darwin
Type "help", "copyright", "credits" or "license" for more information.
(.startup.py)
(imported numpy as np)
(imported matplotlib.pyplot as plt)
(imported scipy.interpolate CubicSpline)
(imported scipy.interpolate interp1d)
(imported os)
(imported sys)
(imported glob)

and if look at the version of scipy in the python2.7 shell, I get :

>>> import scipy
>>> scipy.version.version
'1.2.2'

Where are installed the numpy and scipy libraries for the default python 2.7 on Big Sur 11.3 ? : I tried to look for (with sudo grep -riIHn cubicspline) in /System/Library, and ~/Library/, and in /Library/, but found nothing.

0

There are 0 best solutions below