All these varied answers suggest that many different problems appear as ImportError: numpy.core.multiarray failed to import.
==> So look for more error information before the stack traceback
E.g. steps to reproduce one such problem (these steps worked fine until numpy 1.20 was released):
# set up a virtualenv
pyenv virtualenv 3.8.7 pip-issue-9542
pyenv local pip-issue-9542
# update pip, setuptools
pip install -U pip setuptools
# install 2 pips
pip install --no-cache-dir numpy==1.19.5 cvxpy==1.1.3
# try to load cvxpy
python -c 'import cvxpy'
Output:
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/var/pyenv/versions/pip-issue-9542/lib/python3.8/site-packages/cvxpy/__init__.py", line 18, in <module>
from cvxpy.atoms import *
File "/usr/local/var/pyenv/versions/pip-issue-9542/lib/python3.8/site-packages/cvxpy/atoms/__init__.py", line 20, in <module>
from cvxpy.atoms.geo_mean import geo_mean
File "/usr/local/var/pyenv/versions/pip-issue-9542/lib/python3.8/site-packages/cvxpy/atoms/geo_mean.py", line 20, in <module>
from cvxpy.utilities.power_tools import (fracify, decompose, approx_error, lower_bound,
File "/usr/local/var/pyenv/versions/pip-issue-9542/lib/python3.8/site-packages/cvxpy/utilities/power_tools.py", line 18, in <module>
from cvxpy.atoms.affine.reshape import reshape
File "/usr/local/var/pyenv/versions/pip-issue-9542/lib/python3.8/site-packages/cvxpy/atoms/affine/reshape.py", line 18, in <module>
from cvxpy.atoms.affine.hstack import hstack
File "/usr/local/var/pyenv/versions/pip-issue-9542/lib/python3.8/site-packages/cvxpy/atoms/affine/hstack.py", line 18, in <module>
from cvxpy.atoms.affine.affine_atom import AffAtom
File "/usr/local/var/pyenv/versions/pip-issue-9542/lib/python3.8/site-packages/cvxpy/atoms/affine/affine_atom.py", line 22, in <module>
from cvxpy.cvxcore.python import canonInterface
File "/usr/local/var/pyenv/versions/pip-issue-9542/lib/python3.8/site-packages/cvxpy/cvxcore/python/__init__.py", line 3, in <module>
import _cvxcore
ImportError: numpy.core.multiarray failed to import
The important clue is RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd.
Searching on that can get you to pip issue 9542 and cvxpy issue 1229 which explain what went wrong.
The workarounds in this case are to (a) update to cvxpy>=1.1.10, or (b) update to numpy>=1.20, or (c) update both. You'll have to cope with library changes since the original environment is not reproducible without diving into pip's --no-build-isolation world.
conda update pythontwo times (once to update conda, and again to update python to 2.7.13) fixed the problem. - Jason O.pip install opencv-python==3.4.2.17 numpy==1.14.5worked for me - Markus Weber