在 MacOS Big Sur 11.3 上升级 Python 2.7.16 库

如何解决在 MacOS Big Sur 11.3 上升级 Python 2.7.16 库

为了确认使用 python2 从 scipy 使用 Cubicspline 对插值进行编码的同事的结果,我必须导入 CubicSpline 函数。我知道 python2 已被弃用,但这只是为了验证。

但是当我做一个

from scipy.interpolate import CubicSpline

我有系统的错误信息:

ImportError: cannot import name CubicSpline

所以,我尝试通过以下方式使用 pip-2.7 安装它:

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

python2.7 get-pip.py

之后来自目录 ~/Library/Python/2.7/bin :

./pip2.7 install scipy

但同样的错误,找不到CubicSpline

我有版本:

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

所以python2.7是系统认的python2。

如何在操作系统认安装的 CubicSpline 上安装 python2.7 库?

我必须重新安装所有的 python2.7 框架吗?如果是,如何执行?

更新 1

情况变得更糟了:

在做了 $ python2.7 -m pip install scipy numpy 之后我现在:

$ 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

最后,我决定使用 Macport,但是当我使用时仍然有问题:

$ /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

在 Big Sur,我看到文件 libSystem.B.dylib 不再存在。

如何规避所有这些问题?

更新 2

事情好多了,但还没有全部完成。

我从 MacPorts 中删除python2.7 以及位于 python2* 中的无用的 /usr/local/bin/ 类型的二进制文件

现在,我只有来自 python2.7 的二进制 /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","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
>>>

如您所见,numpyscipy 加载良好,但此行仍然存在此问题:from scipy.interpolate import CubicSpline

我想知道这个库 CubicSpline 的位置。确实,最近可以make run一个“python2.7”的代码版本,这个函数CubicSpline的加载和使用都没有问题。

numpy 的 OS System 版本的 scipypython2.7 的存储位置

更新 3

我终于找到了问题的来源。 CubicSpline 似乎只适用于 scipy > 0.18。但是在我的 MacBook 上,如果我这样做:

$ import scipy
  scipy.version.version

我明白了:

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

有没有办法升级 MacOS Big Sur Python 2.7 认系统的 scipy(我的意思是不使用 Brew/Macports)?

更新 4

我什么都不懂,在装有 Big Sur 11.3 的类似 MacBook Pro 上,如果我懂的话:

/usr/bin/python2.7

我明白了:

Python 2.7.16 (default,"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)

如果在 python2.7 shell 中查看 scipy 的版本,我得到:

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

numpyscipypython 2.7Big Sur 11.3 库安装在哪里? :我试图在 sudo grep -riIHn cubicspline/System/Library~/Library/ 中寻找(使用 /Library/),但一无所获。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?