Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError: numpy.core.multiarray failed to import #6270

Open
1fish2 opened this issue Feb 16, 2019 · 2 comments
Open

ImportError: numpy.core.multiarray failed to import #6270

1fish2 opened this issue Feb 16, 2019 · 2 comments
Labels
C: cache Dealing with cache and files in it state: needs discussion This needs some more discussion type: support User Support

Comments

@1fish2
Copy link

1fish2 commented Feb 16, 2019

Environment

  • pip version: 19.0.2
  • Python version: 2.7.15
  • OS: macOS

Description
I spent a few hours debugging

ImportError: numpy.core.multiarray failed to import

NumPy imports just fine but an installed package could not import numpy. (I don't actually know if that installed package could ever import numpy.)

Lots of discussions with this error message on the web, including the TensorFlow discussion with various approaches and limited successes indicate that other people have wrangled with this problem as well.

After ruling out a bunch of hypotheses (reboot; reinstall the pip that can't import numpy; reinstall python; reinstall numpy; uninstall alternate pyenv virtualenvs that contained other versions of numpy; create a minimal test virtualenv containing only numpy, pip, setuptools, wheel, and the package that can't import numpy; uninstall all other pyenv virtualenvs that contain numpy except the system's own python which is locked by System Integrity Protection), I finally fixed it with this:

pip install --force-reinstall --no-cache-dir package-that-can't-import-numpy

In other words, re-download and reinstall the calling package. (In my case, the relevant package was stochastic-arrow==0.1.4.)

Before- & after-tests showed that this step fixed the problem in my minimal test virtualenv and separately in my main working virtualenv.

Thinking about likely causes in common to the reported cases around the web leads to these ideas:

  • Hypothesis 1: A bug in pip can lead to cached packages with bad linkage to numpy.

  • Hypothesis 2: A bug in numpy's setup.py can lead to cached packages with bad linkage to numpy.

Expected behavior
Packages that happily import numpy.

How to Reproduce
Alas, I do not know how to get the computer back into the broken state.

Output

$ python -c 'import numpy'
$ python -c 'from arrow import StochasticSystem'
ImportError: No module named _multiarray_umath
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/var/pyenv/versions/test/lib/python2.7/site-packages/arrow/__init__.py", line 1, in <module>
    from reference import derive_reactants, calculate_dependencies, evolve, GillespieReference
  File "/usr/local/var/pyenv/versions/test/lib/python2.7/site-packages/arrow/reference.py", line 6, in <module>
    import obsidian
ImportError: numpy.core.multiarray failed to import
@pradyunsg pradyunsg added the S: needs triage Issues/PRs that need to be triaged label May 27, 2019
@chrahunt chrahunt added C: cache Dealing with cache and files in it state: needs discussion This needs some more discussion type: support User Support labels Jul 26, 2019
@triage-new-issues triage-new-issues bot removed the S: needs triage Issues/PRs that need to be triaged label Jul 26, 2019
@chrahunt
Copy link
Member

When we download source distributions (which stochastic-arrow provides), we typically build a wheel and cache and install it. For legacy builds (for projects that don't use pyproject.toml, the build takes place in whatever the current environment is using whatever dependencies are available. If stochastic-arrow was installed in an environment with a numpy==1.X and then installed in another environment with numpy==1.Y, the latter environment would get the cached wheel and that could potentially cause issues like what you're seeing.

There are some related issues like #2882, however I can't find one that matches this exactly.

@chrahunt
Copy link
Member

#4582 is the issue I was thinking of, specifically this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: cache Dealing with cache and files in it state: needs discussion This needs some more discussion type: support User Support
Projects
None yet
Development

No branches or pull requests

3 participants