关于python:如何升级NumPy? 您所在的位置:网站首页 树莓派安装numpy 关于python:如何升级NumPy?

关于python:如何升级NumPy?

2023-02-23 21:45| 来源: 网络整理| 查看: 265

使用Homebrew(brew)安装OpenCV时,每当运行以下命令测试python -c"import cv2"时,都会出现此问题:

1234RuntimeError: module compiled against API version 9 but this version of numpy is 6 Traceback (most recent call last):   File"", line 1, in ImportError: numpy.core.multiarray failed to import

我尝试升级NumPy,但这很令人困惑:

123>>> import numpy >>> print numpy.__version__ 1.6.1

当我运行brew升级NumPy时,出现了以下问题:

12brew install -u numpy Warning: numpy-1.9.1 already installed

当我卸载它时:

12sudo pip install numpy Requirement already satisfied (use --upgrade to upgrade): numpy in ./anaconda/lib/python2.7/site-packages

我已经关注了这个问题,并从Mac中删除了Anaconda。

12pip install numpy Requirement already satisfied (use --upgrade to upgrade): numpy in /Library/Python/2.7/site-packages

但是什么都没有改变。 如何将NumPy版本链接到OpenCV?

因为我们在系统中有两个NumPy安装。一个由Homebrew安装,第二个由pip安装。因此,为了解决该问题,我们需要删除一个,并使用OpenCV的默认NumPy安装。

检查路径,

12import numpy print numpy.__path__

并使用rm手动将其删除。

相关讨论 它似乎不适用于Mac OSX El Capitan,因为(a)它拒绝删除SystemLibraryFrameworksPython.frameworkVersions2.7Extraslibpython中的numpys文件夹,并且(b)通常这不是一个好方法, @ИванГеоргиев:那还有什么呢? 非常感谢,这解决了我投入太多时间的版本冲突的问题。 Debian python和pip似乎生活在usrlib,\usrlocallib和~.locallib中。

如果您已经拥有旧版本的NumPy,请使用以下命令:

1pip install numpy --upgrade

如果仍然无法正常运行,请尝试:

1pip install numpy --upgrade --ignore-installed

当您的系统上有两个版本的NumPy时,会发生您提到的错误。如您所述,导入的NumPy的版本仍未升级,因为您尝试通过pip对其进行升级(它将升级'/Library/Python/2.7/site-packages'中现有的版本)。

但是,Python仍从 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy'加载预安装软件包所在的软件包。

为了升级该版本,您必须使用easy_install。解决此问题的另一种方法是使用virtualenv并根据您的所有要求设置新环境。

相关讨论 搜索的sudo easy_install numpy添加了最新的numpy路径(我的sudo pip install numpy已存在的coz)。 完美的解决方案。 有类似的问题。 sudo easy_install numpy。 它删除了以前的内容,并更新了最新的内容。 追溯Searching for numpy Best match: numpy 1.11.2 Removing numpy 1.8.2 from easy-install.pth file Adding numpy 1.11.2 to easy-install.pth file 这也对我有用(首先使用pip --ignore-installed安装它,然后"链接"它,以便python使用sudo easy_install numpy找到它)。 其他解决方案没有用。 sudo easy_install numpy对我不起作用,但是sudo pip install --ignore-installed numpy确实很好用。 感谢BjornW。

仅供参考,当您使用或导入TensorFlow时,可能会发生类似的错误,例如(由NumPy引起):

123456789101112131415161718192021RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9 Traceback (most recent call last):   File"", line 1, in   File"/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 23, in     from tensorflow.python import *   File"/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 60, in     raise ImportError(msg) ImportError: Traceback (most recent call last):   File"/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 49, in     from tensorflow.python import pywrap_tensorflow   File"/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 28, in     _pywrap_tensorflow = swig_import_helper()   File"/usr/local/lib/python2.7/dist-packages/tensorflow/python/pywrap_tensorflow.py", line 24, in swig_import_helper     _mod = imp.load_module('_pywrap_tensorflow', fp, pathname, description) ImportError: numpy.core.multiarray failed to import Error importing tensorflow.  Unless you are using bazel, you should not try to import tensorflow from its source directory; please exit the tensorflow source tree, and relaunch your python interpreter from there.

我按照Elmira和Drew的解决方案sudo easy_install numpy进行了工作!

123456789sudo easy_install numpy Searching for numpy Best match: numpy 1.11.3 Removing numpy 1.8.2 from easy-install.pth file Adding numpy 1.11.3 to easy-install.pth file Using /usr/local/lib/python2.7/dist-packages Processing dependencies for numpy Finished processing dependencies for numpy

之后,我可以使用TensorFlow而不会出现错误。

因为您安装了多个版本的NumPy。

尝试几次pip uninstall numpy和pip list | grep numpy,直到看不到pip list | grep numpy的输出。

然后pip install numpy将为您提供NumPy的最新版本。

我尝试使用sudo pip uninstall numpy代替,因为rm最初不起作用。

希望有帮助。

卸载后重新安装。

如果您没有遇到任何权限错误

1pip install -U numpy

尝试:

1pip install --user -U numpy 相关讨论 我知道这已经有两年了,但是真棒

这对我有用:

1pip install numpy --upgrade

全部都一样。

1   sudo easy_install numpy

我的回溯

123456789Searching for numpy Best match: numpy 1.13.0 Adding numpy 1.13.0 to easy-install.pth file Using /Library/Python/2.7/site-packages Processing dependencies for numpy

安装pytorch后,使用时出现类似错误:

1import torch

删除NumPy并没有帮助(我实际上重命名了NumPy,所以在它无效后我又恢复了)。以下命令对我有用:

12sudo pip install numpy --upgrade sudo easy_install numpy 更新numpy

对于python 2

1pip install numpy --upgrade

您还需要升级表,以获取numpy的更新版本。所以,

1pip install tables --upgrade

对于python 3

1pip3 install numpy --upgrade

同样,python3的表:-

1pip3 install tables --upgrade

注意:

您需要检查使用的是哪个python版本。适用于python 2.7+的pip或适用于python 3+的pip3

如果您被限制在没有root用户访问权限的机器上,那么最好处理自定义的Python安装。

Anaconda的安装就像一个魅力:

安装软件包(SciPy.org) Anaconda Python / R Distribution-下载

安装后,

$ /xxx/devTools/python/anaconda/bin/pip list --format=columns | grep numpy

numpy 1.13.3 numpydoc 0.7.0



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有