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 is misleading when importing an old multiarray in NumPy 1.16.1 #12976

Closed
tbekolay opened this issue Feb 15, 2019 · 15 comments
Closed

Comments

@tbekolay
Copy link

tbekolay commented Feb 15, 2019

I install NumPy from source. I recently checked out the 1.16.1 tag and when I imported the built and installed NumPy, I get

ImportError: Something is wrong with the numpy installation. While importing we detected an older version of numpy in ['/home/tbekolay/.virtualenvs/pytest/lib/python3.7/site-packages/numpy']. One method of fixing this is to repeatedly uninstall numpy until none is found, then reinstall this version.

The directory pointed there is the directory of the currently installed NumPy. When I looked in numpy/core/__init__.py, I saw the other error message, which includes the git clean -xdf command. When I ran this in the git repo, I could build and install successfully. So I believe it would be useful for both of those cases to include the instructions that normally occur when multiarray can't be imported. (line 19 in core/__init__.py).

Alternatively, we could detect if the path given by sys.modules['numpy'].__path__ is the same as the one we would get by looking at __file__ to determine if it is a weird version error or just an old multiarray sticking around.

Reproducing code example:

Check out an old release like 1.15.1 and build from source. Check out 1.16.1, build again and install. Then

import numpy as np

Error message:

ImportError: Something is wrong with the numpy installation. While importing we detected an older version of numpy in ['/home/tbekolay/.virtualenvs/pytest/lib/python3.7/site-packages/numpy']. One method of fixing this is to repeatedly uninstall numpy until none is found, then reinstall this version.

Numpy/Python version information:

1.16.1 3.7.2+ (default, Feb  2 2019, 14:31:48) 
[GCC 8.2.0]
@charris
Copy link
Member

charris commented Feb 15, 2019

@mattip I think we should try using __import__ when importing ufunc.py and multiarray.py, it allows forcing relative imports only without exploring higher level directories. See https://docs.python.org/3/library/functions.html#__import__, I think level=1 would do it.

@mattip
Copy link
Member

mattip commented Feb 16, 2019

@charris what error scenario would that mitigate? It would not help in this case.

@eric-wieser
Copy link
Member

eric-wieser commented Feb 16, 2019

Pretty sure that the description of __import__ is out of date, and it probably respects pep420 packages in the same way as any other import

@charris
Copy link
Member

charris commented Feb 16, 2019

@eric-wieser The documentation is for Python 3.7.2. What we need is a way to replicate the problem so we can test things.

@rgommers
Copy link
Member

What we need is a way to replicate the problem so we can test things.

The description of this issue provides one. Faster way: use your regular in-place dev build, and just copy in a multiarray.so (grab from a wheel or whatever).

@charris
Copy link
Member

charris commented Feb 16, 2019

@rgommers So the problem is duplicate files with different extensions in the same directory?

@charris charris closed this as completed Feb 16, 2019
@rgommers
Copy link
Member

@rgommers So the problem is duplicate files with different extensions in the same directory?

Unless I'm missing something, yes. It's this: https://github.com/numpy/numpy/pull/12850/files

Reports on this stuff are daily, I think we need a better solution here. I didn't follow very closely though, there were multiple proposed solutions but no water tight ones yet.

@mattip
Copy link
Member

mattip commented Feb 16, 2019

The daily reports are a different issue altogether. Anaconda recently broke setting os.environ['PATH'].

@rgommers
Copy link
Member

@mattip you're right, that one is worse. This is also common though, e.g. gh-12938, gh-12736, gh-12826, #12957 (comment)

@PorkPy
Copy link

PorkPy commented Feb 27, 2019

I had this error. It was due to multiple instances of numpy. It seems python is looking for numpy packages not numpy installations. Following the advice from the error handler in bash and uninstalling numpy won't remove the error because python can still see the uninstalled packages.
If these versions of numpy are needed for some other application, for the time being, just move them onto your desktop where python can't find them. This should resolve the error.
Hope this helps.
Edit: You may need to use 'pip3 install numpy' when using python3.
Edit2: I also can't use my code with python3.6 or 3.7 even if I upgrade numpy. Only 3.5 for me. If I try to use python >3.5 I get "ImportError: cannot import name 'multiarray' ".

@rgommers
Copy link
Member

It seems python is looking for numpy packages not numpy installations.

that isn't a well-defined distinction

uninstalling numpy won't remove the error because python can still see the uninstalled packages.

then the uninstall was incomplete. uninstall with pip should remove both site-packages/numpy/ and the corresponding .dist-info or .egg-info directories.

@OnlyBelter
Copy link

If you use conda, you can update numpy by
conda update -n env_name -c defaults numpy

@wasiuyahya
Copy link

Use pip uninstall numpy
It's due to the duplicate of numpy

@nguyenvulong
Copy link

Try
pip uninstall numpy and
sudo pip uninstall numpy

repeatedly until you purge all numpy versions.
Replace pip by pip3 if you use python3.

@ctkqiang
Copy link

For Ubuntu:

I solve it by sudo apt-get install python3-numpy && sudo apt-get install python-numpy.
Hope this help.

@numpy numpy locked as resolved and limited conversation to collaborators May 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants