解決Numpy報(bào)錯(cuò):ImportError: numpy.core.multiarray failed
Numpy報(bào)錯(cuò):ImportError: numpy.core.multiarray failed
導(dǎo)入自定義的 python 模塊時(shí)
出現(xiàn)以下報(bào)錯(cuò):
ImportError: numpy.core.multiarray failed to import
from .cv2 import *
ImportError: numpy.core.multiarray failed to import
原因
numpy 版本過低或者過高
解決
查看numpy 版本:
pip show numpy
我當(dāng)前環(huán)境中的 numpy 版本是:
Version: 1.16.5
升級(jí):
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
結(jié)果還是不行,遂給 numpy 降級(jí):pip install -U numpy==1.14.0(之前是 1.16.5)
不僅造成了不少?zèng)_突,而且沒效果:
(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,
同時(shí)更新 opencv 的版本試試,這是當(dāng)前版本:

本身就是最新版本,嘗試過沒用。

后來發(fā)現(xiàn),問題在于
①import numpy as numpy
會(huì)報(bào)錯(cuò):
ImportError: numpy.core.multiarray failed to import
② import cv2
會(huì)報(bào)錯(cuò):
AttributeError: module 'logging' has no attribute 'Handler'
最后發(fā)現(xiàn),最為離奇詭異的是,在不同的文件夾下面執(zhí)行相同的代碼(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 <module>
import numpy as np
File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/numpy/__init__.py", line 187, in <module>
from .testing import Tester
File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/site-packages/numpy/testing/__init__.py", line 10, in <module>
from unittest import TestCase
File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/unittest/__init__.py", line 59, in <module>
from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
File "/Users/robin/software/anaconda3/envs/tensorflow/lib/python3.6/unittest/case.py", line 278, in <module>
class _CapturingHandler(logging.Handler):
AttributeError: module 'logging' has no attribute 'Handler'Process finished with exit code 1
最后我放棄治療了,新建了一個(gè)文件夾,將文件移動(dòng)過去了,就當(dāng)做 Pycharm 抽風(fēng)了吧
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- 關(guān)于Python ImportError: No module named 通用解決方法
- 解決ImportError:cannot import name ‘Flatten‘ from ‘torch.nn‘問題
- python之ImportError:模塊引入異常問題
- python解決報(bào)錯(cuò)ImportError: Bad git executable.問題
- 安裝pyhttpx解決ImportError: DLL load failed錯(cuò)誤
- 關(guān)于sklearn包導(dǎo)入錯(cuò)誤:ImportError:?cannot?import?name Type解決方案
- Python報(bào)錯(cuò)ImportError:?IProgress?not?found.?Please?update?jupyter?and?ipywidgets解決
- Python報(bào)錯(cuò)ImportError: No module named ‘missing_module‘的解決方法
- Python解決“ImportError:?Couldn‘t?import?Django”問題全攻略
相關(guān)文章
python中偏函數(shù)partial用法實(shí)例分析
這篇文章主要介紹了python中偏函數(shù)partial用法,實(shí)例分析了偏函數(shù)partial的功能、定義及使用方法,需要的朋友可以參考下2015-07-07
Python設(shè)計(jì)模式之原型模式實(shí)例詳解
這篇文章主要介紹了Python設(shè)計(jì)模式之原型模式,結(jié)合實(shí)例形式較為詳細(xì)的分析了Python原型模式的概念、原理、用法及相關(guān)操作注意事項(xiàng),需要的朋友可以參考下2019-01-01
簡(jiǎn)單談?wù)凱ython面向?qū)ο蟮南嚓P(guān)知識(shí)
由于馬上就要期末考試了,正在抓緊時(shí)間復(fù)習(xí) 所以這一篇就拖了很久,抱歉啦~ 今天會(huì)說說: 屬性私有,方法私有,重寫,魔術(shù)方法,需要的朋友可以參考下2021-01-01
Python標(biāo)準(zhǔn)庫06之子進(jìn)程 (subprocess包) 詳解
本篇文章主要介紹了Python標(biāo)準(zhǔn)庫06之子進(jìn)程 (subprocess包) 詳解,具有一定的參考價(jià)值,有興趣的同學(xué)可以了解一下。2016-12-12
對(duì)python while循環(huán)和雙重循環(huán)的實(shí)例詳解
今天小編就為大家分享一篇對(duì)python while循環(huán)和雙重循環(huán)的實(shí)例詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-08-08

