栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Numpy报错:ImportError: numpy.core.multiarray failed to import

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Numpy报错:ImportError: numpy.core.multiarray failed to import

导入自定义的 python 模块时,出现以下报错:

importError: numpy.core.multiarray failed to import
    from .cv2 import *
importError: numpy.core.multiarray failed to import

原因:

numpy 版本过低或者过高

解决:

  • 查看numpy 版本:pip show numpy
    我当前环境中的 numpy 版本是:Version: 1.16.5
  • 升级:pip install -U numpy
(tensorflow) Robin-macbook-pro:~ robin$ pip install -U numpy
Collecting numpy
  Downloading https://files.pythonhosted.org/packages/6a/9d/984f87a8d5b28b1d4afc042d8f436a76d6210fb582214f35a0ea1db3be66/numpy-1.19.5-cp36-cp36m-macosx_10_9_x86_64.whl (15.6MB)
     |████████████████████████████████| 15.6MB 1.3MB/s 
ERROR: tensorflow 1.13.1 has requirement protobuf>=3.6.1, but you'll have protobuf 3.6.0 which is incompatible.
Installing collected packages: numpy
  Found existing installation: numpy 1.16.5
    Uninstalling numpy-1.16.5:
      Successfully uninstalled numpy-1.16.5
Successfully installed numpy-1.19.5

结果还是不行,遂给 numpy 降级:pip install -U numpy==1.14.0(之前是 1.16.5)

不仅造成了不少冲突,而且没效果:

(tensorflow) Robin-macbook-pro:~ robin$ pip install -U numpy==1.14.0
Collecting numpy==1.14.0
  Downloading https://files.pythonhosted.org/packages/33/c4/1ea5344793c159556110e42c94c9374cb08ce2a2727374cd467bd97f6579/numpy-1.14.0-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (4.7MB)
     |████████████████████████████████| 4.7MB 230kB/s 
ERROR: tensorflow 1.13.1 has requirement protobuf>=3.6.1, but you'll have protobuf 3.6.0 which is incompatible.
ERROR: pmdarima 1.3.0 has requirement numpy>=1.16, but you'll have numpy 1.14.0 which is incompatible.
ERROR: phik 0.9.8 has requirement numpy>=1.15.4, but you'll have numpy 1.14.0 which is incompatible.
ERROR: librosa 0.8.0 has requirement numpy>=1.15.0, but you'll have numpy 1.14.0 which is incompatible.
ERROR: astropy 4.0 has requirement numpy>=1.16, but you'll have numpy 1.14.0 which is incompatible.
Installing collected packages: numpy
  Found existing installation: numpy 1.19.5
    Uninstalling numpy-1.19.5:
      Successfully uninstalled numpy-1.19.5
Successfully installed numpy-1.14.0

还是不行:

将numpy更到最新版本:pip install -U numpy,
同时更新 opencv 的版本试试,这是当前版本:


本身就是最新版本,尝试过没用。

后来发现,问题在于

  • ①import numpy as numpy
    会报错:importError: numpy.core.multiarray failed to import
  • ② import cv2
    会报错:AttributeError: module 'logging' has no attribute 'Handler'

最后发现,最为离奇诡异的是,在不同的文件夹下面执行相同的代码(import numpy as np)是没有任何问题的

(1)

/Users/robin/software/anaconda3/envs/tensorflow/bin/python3.6 /Users/robin/MLcode/Pycharm_Project/tensorflow/2021/0823_face_recognition_environment/test.py

Process finished with exit code 0

(2)

/Users/robin/software/anaconda3/envs/tensorflow/bin/python3.6 /Users/robin/MLcode/Pycharm_Project/tensorflow/2021/0823_face_recognition_environment/ui/test.py
Traceback (most recent call last):
  File "/Users/robin/MLcode/Pycharm_Project/tensorflow/2021/0823_face_recognition_environment/ui/test.py", line 1, in 
    import numpy as np
  File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/numpy/__init__.py", line 187, in 
    from .testing import Tester
  File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/numpy/testing/__init__.py", line 10, in 
    from unittest import TestCase
  File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/unittest/__init__.py", line 59, in 
    from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
  File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/unittest/case.py", line 278, in 
    class _CapturingHandler(logging.Handler):
AttributeError: module 'logging' has no attribute 'Handler'

Process finished with exit code 1

最后我放弃治疗了,新建了一个文件夹,将文件移动过去了,就当做 Pycharm 抽风了吧

浪费一下午时间…!!!!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/280716.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号