解決Numpy報錯:ImportError: numpy.core.multiarray failed
Numpy報錯:ImportError: numpy.core.multiarray failed
導入自定義的 python 模塊時
出現(xiàn)以下報錯:
ImportError: numpy.core.multiarray failed to import
from .cv2 import *
ImportError: numpy.core.multiarray failed to import
原因
numpy 版本過低或者過高
解決
查看numpy 版本:
pip show numpy
我當前環(huán)境中的 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
結(jié)果還是不行,遂給 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 的版本試試,這是當前版本:
本身就是最新版本,嘗試過沒用。
后來發(fā)現(xiàn),問題在于
①import numpy as numpy
會報錯:
ImportError: numpy.core.multiarray failed to import
② import cv2
會報錯:
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
最后我放棄治療了,新建了一個文件夾,將文件移動過去了,就當做 Pycharm 抽風了吧
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
- 關(guān)于Python ImportError: No module named 通用解決方法
- 解決ImportError:cannot import name ‘Flatten‘ from ‘torch.nn‘問題
- python之ImportError:模塊引入異常問題
- python解決報錯ImportError: Bad git executable.問題
- 安裝pyhttpx解決ImportError: DLL load failed錯誤
- 關(guān)于sklearn包導入錯誤:ImportError:?cannot?import?name Type解決方案
- Python報錯ImportError:?IProgress?not?found.?Please?update?jupyter?and?ipywidgets解決
- Python報錯ImportError: No module named ‘missing_module‘的解決方法
- Python解決“ImportError:?Couldn‘t?import?Django”問題全攻略
相關(guān)文章
Python標準庫06之子進程 (subprocess包) 詳解
本篇文章主要介紹了Python標準庫06之子進程 (subprocess包) 詳解,具有一定的參考價值,有興趣的同學可以了解一下。2016-12-12對python while循環(huán)和雙重循環(huán)的實例詳解
今天小編就為大家分享一篇對python while循環(huán)和雙重循環(huán)的實例詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-08-08