You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Attribute Error after installing v1.16.0 because pip is not uninstalling #12736
I pip installed the latest numpy and get the below error. The error goes away if I roll back to v1.15.4.
The most closely related issue I could find is #12028.
Reproducing code example:
importnumpyasnp
Error message:
Traceback (most recent call last):
File "/home/trey/script.py", line 6, in <module>
import numpy as np
File "/home/trey/.local/lib/python3.6/site-packages/numpy/__init__.py", line 142, in <module>
from . import core
File "/home/trey/.local/lib/python3.6/site-packages/numpy/core/__init__.py", line 59, in <module>
from . import numeric
File "/home/trey/.local/lib/python3.6/site-packages/numpy/core/numeric.py", line 3093, in <module>
from . import fromnumeric
File "/home/trey/.local/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 17, in <module>
from . import _methods
File "/home/trey/.local/lib/python3.6/site-packages/numpy/core/_methods.py", line 158, in <module>
_NDARRAY_ARRAY_FUNCTION = mu.ndarray.__array_function__
AttributeError: type object 'numpy.ndarray' has no attribute '__array_function__'
Numpy/Python version information:
1.16.0
3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0]
Looks like you have a mix of two versions. Is this installed from source or wheels? Anyway, you might try deleting the current NumPy installs in your local directory before installing 1.16.
I'm faced the same issue.
We're using Ubuntu 16.04 based Docker containers in our CI and using Tensorflow from pre-built wheel file which contains requirement 'numpy>=1.13.3'. I've got numpy version updated automatically from PyPI to 1.16.0 version today and my tests have failed with the following error on numpy import:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/numpy/__init__.py", line 142, in <module>
from . import core
File "/usr/local/lib/python3.5/dist-packages/numpy/core/__init__.py", line 59, in <module>
from . import numeric
File "/usr/local/lib/python3.5/dist-packages/numpy/core/numeric.py", line 3093, in <module>
from . import fromnumeric
File "/usr/local/lib/python3.5/dist-packages/numpy/core/fromnumeric.py", line 17, in <module>
from . import _methods
File "/usr/local/lib/python3.5/dist-packages/numpy/core/_methods.py", line 158, in <module>
_NDARRAY_ARRAY_FUNCTION = mu.ndarray.__array_function__
AttributeError: type object 'numpy.ndarray' has no attribute '__array_function__'
I've started to look at this and tried previous tag of the image. It contains numpy version 1.15.4. I've tried to upgrade numpy manually and it was ok:
$ sudo -E pip3 install --upgrade numpy
Installing collected packages: numpy
Successfully installed numpy-1.16.0
$ python3
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>>
So I've decided to try to reinstall numpy manually inside container from "corrupted" image:
sudo pip3 uninstall numpy
But when I've tried to install it again I've got the following:
Requirement already satisfied: numpy in /usr/local/lib/python3.5/dist-packages
I've checked /usr/local/lib/python3.5/dist-packages/numpy directory and found that some files were here:
$ ls /usr/local/lib/python3.5/dist-packages/numpy
__pycache__ _import_tools.py add_newdocs.py core distutils testing
I've removed numpy directories and tried to install it again, and it worked.
So it seems that upgrade from 1.15.4 went fine, but from 1.13.1 (which was installed in "corrupted" image prior I've tried to upgrade numpy) something went wrong. May be I should upgrade pip?
$ pip3 --version
pip 9.0.3 from /usr/local/lib/python3.5/dist-packages (python 3.5)
Reacted by KWL, Haitao Chen, Atinesh Singh, ZHANG Bowen, Gokul NC, Soumik Ranjan Dasgupta, Deep, grigorizaika, Tess Smidt, Aman Chaudhary and 6 more
Similar to @oxygenxo's situation, I had an older version of pip (9.0.1) and the previously installed version of numpy was likely two or three major versions behind.
Simply uninstalling numpy altogether before reinstalling v1.16.0 fixes the issue for me.
I just bumped into the same issue, but I had the latest versions of pip (18.1) and numpy (1.15.4) (on Windows). It looks like something goes wrong in the pip upgrade process.
Completely uninstalling / reinstalling numpy seems effectively to solve it.
Reacted by Tongfei Chen, Haitao Chen, Kopal Agarwal, Matt, Kevin Arvai and Dilawar Singh
Might it be that pip is not removing the multiarray, umath c-extension modules when upgrading? Since we unified them into one c-extension module _multiarray_umath, we created pure-python shims. But if there is a python file name.py and a c-extension module name.so or name.pyd, the c-extension module will be given preference.
Hmm, the troublesome line is gone in master. AFAICT, _NDARRAY_ARRAY_FUNCTION defined in that file is not used anywhere. @shoyer is that a development artifact that got left behind?
@charris it is in the 1.16.0 tagged version of _methods.py. Note this is just a symptom of a broken installation, and a good one since it may be hard to detect they are using old c-extensions without that crash
@mattip, I think it is both :) Yes, it is gone in master with the move to c for __array_function__, but in 1.16 it is defined in two places, and the definition in _methods.py seems to never be referenced.
Yes, but without giving us more information such as a reproduction or by minimum the conda + pip versions and how did it happen, it doesn't help too much.
@wenzao you have numpy-base 1.15.4 and numpy 1.16 that is the core of the issue... I dont know why anaconda has that split, or how it goes together, but maybe someone should open an issue on conda-forge's numpy pacakage (and maybe anaconda).
I had the same problem on my machine running Ubuntu 18.06. I installed 1.16.0 and would get the attribute error. If I rolled back to 1.15.4 the attribute error would not appear. I had to pip uninstall numpy for every version of 1.15.X that I had on my machine (I had several) and only then could I install 1.16.0 without getting an attribute error.
So, as advised above, the next Travis config will help you:
before_install:
# Travis pre-installs an old version of numpy.
# It conflicts with the latest one, see https://github.com/numpy/numpy/issues/12736
- pip uninstall -y numpy # will uninstall your numpy from cache
- pip uninstall -y numpy # will uninstall preinstalled numpy 1.15.2
- pip uninstall -y numpy # just in case
I cannot say I am happy with this workaround, but until Travis will update their build packs we can do nothing.
(voice-clone) C:\Users\DELL\Desktop\voice>python demo_cli.py
Traceback (most recent call last):
File "C:\Users\DELL\Desktop\voice\demo_cli.py", line 5, in
import librosa
File "C:\Users\DELL\anaconda3\envs\voice-clone\Lib\site-packages\librosa_init_.py", line 211, in
from . import core
File "C:\Users\DELL\anaconda3\envs\voice-clone\Lib\site-packages\librosa\core_init_.py", line 9, in
from .constantq import * # pylint: disable=wildcard-import
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\DELL\anaconda3\envs\voice-clone\Lib\site-packages\librosa\core\constantq.py", line 1058, in
dtype=np.complex,
^^^^^^^^^^
File "C:\Users\DELL\anaconda3\envs\voice-clone\Lib\site-packages\numpy_init_.py", line 324, in getattr
raise AttributeError(former_attrs[attr])
AttributeError: module 'numpy' has no attribute 'complex'. np.complex was a deprecated alias for the builtin complex. To avoid this error in existing code, use complex by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.complex128 here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations. Did you mean: 'complex_'?
Activity
charris commentedon Jan 14, 2019
Looks like you have a mix of two versions. Is this installed from source or wheels? Anyway, you might try deleting the current NumPy installs in your local directory before installing 1.16.
ababushk commentedon Jan 14, 2019
I'm faced the same issue.
We're using Ubuntu 16.04 based Docker containers in our CI and using Tensorflow from pre-built wheel file which contains requirement 'numpy>=1.13.3'. I've got numpy version updated automatically from PyPI to 1.16.0 version today and my tests have failed with the following error on numpy import:
I've started to look at this and tried previous tag of the image. It contains numpy version 1.15.4. I've tried to upgrade numpy manually and it was ok:
So I've decided to try to reinstall numpy manually inside container from "corrupted" image:
But when I've tried to install it again I've got the following:
I've checked
/usr/local/lib/python3.5/dist-packages/numpydirectory and found that some files were here:I've removed numpy directories and tried to install it again, and it worked.
So it seems that upgrade from 1.15.4 went fine, but from 1.13.1 (which was installed in "corrupted" image prior I've tried to upgrade numpy) something went wrong. May be I should upgrade pip?
treyenelson commentedon Jan 14, 2019
@charris It was originally installed via pip.
Similar to @oxygenxo's situation, I had an older version of pip (9.0.1) and the previously installed version of numpy was likely two or three major versions behind.
Simply uninstalling numpy altogether before reinstalling v1.16.0 fixes the issue for me.
kalbermattenm commentedon Jan 14, 2019
I just bumped into the same issue, but I had the latest versions of pip (18.1) and numpy (1.15.4) (on Windows). It looks like something goes wrong in the pip upgrade process.
Completely uninstalling / reinstalling numpy seems effectively to solve it.
mattip commentedon Jan 14, 2019
Might it be that pip is not removing the
multiarray,umathc-extension modules when upgrading? Since we unified them into one c-extension module_multiarray_umath, we created pure-python shims. But if there is a python filename.pyand a c-extension modulename.soorname.pyd, the c-extension module will be given preference.mattip commentedon Jan 14, 2019
You have a numpy in your image and you
pip installanother one or do youpip install --upgrade?[-]Attribute Error with v1.16.0[/-][+]Attribute Error after installing v1.16.0[/+]kalbermattenm commentedon Jan 14, 2019
I did a
pip install -r ...with an updated requirement file which is automatically updated through greenkeeper.mattip commentedon Jan 14, 2019
I am not a pip expert, is
pip install -r <file>supposed to calluninstallwhen it discovers a stale version?charris commentedon Jan 14, 2019
I suspect this problem is longstanding, but invisible until we added the attribute to
ndarrayand used it in_methods.py.charris commentedon Jan 14, 2019
Hmm, the troublesome line is gone in master. AFAICT,
_NDARRAY_ARRAY_FUNCTIONdefined in that file is not used anywhere. @shoyer is that a development artifact that got left behind?mattip commentedon Jan 14, 2019
Pip documentation says they uninstall before installing a new version. But maybe the older version is from an
apt-get, notpip?mattip commentedon Jan 14, 2019
@charris it is in the 1.16.0 tagged version of
_methods.py. Note this is just a symptom of a broken installation, and a good one since it may be hard to detect they are using old c-extensions without that crashmattip commentedon Jan 14, 2019
@kalbermattenm, @treyenelson, @oxygenxo: was the old version
pip-installed or was it part of some other installation (apt,yum, anaconda, ...)charris commentedon Jan 14, 2019
@mattip, I think it is both :) Yes, it is gone in master with the move to c for
__array_function__, but in 1.16 it is defined in two places, and the definition in_methods.pyseems to never be referenced.59 remaining items
dmitriyshashkin commentedon Jan 24, 2019
I also had the same problem with pip from conda
tzickel commentedon Jan 24, 2019
Yes, but without giving us more information such as a reproduction or by minimum the conda + pip versions and how did it happen, it doesn't help too much.
wenzao commentedon Jan 25, 2019
I rolled back to v1.15 and it's working now.
tzickel commentedon Jan 25, 2019
@wenzao you have numpy-base 1.15.4 and numpy 1.16 that is the core of the issue... I dont know why anaconda has that split, or how it goes together, but maybe someone should open an issue on conda-forge's numpy pacakage (and maybe anaconda).
blondegeek commentedon Jan 25, 2019
I had the same problem on my machine running Ubuntu 18.06. I installed 1.16.0 and would get the attribute error. If I rolled back to 1.15.4 the attribute error would not appear. I had to pip uninstall numpy for every version of 1.15.X that I had on my machine (I had several) and only then could I install 1.16.0 without getting an attribute error.
bwanglzu commentedon Jan 28, 2019
@elliothe thanks you saved my day!
.... do this until you can not uninstall numpy anymore
ubuntu 18.04, python 3.5.
kellyfj commentedon Jan 29, 2019
This sequence of successive uninstalls fixed it for me
[grizzly] Fix recipe for numpy issue numpy/numpy#12736.
mattip commentedon Mar 6, 2019
Closing. We now detect this and emit a better error message.
amureki commentedon Mar 13, 2019
Just a small update for everyone who is using Travis and struggling with this issue and can't figure out the root cause (as we did).
Travis preinstalls 1.15.2 on Trusty and Precise build environments:
https://docs.travis-ci.com/user/reference/precise
https://docs.travis-ci.com/user/reference/trusty
(search for numpy)
So, as advised above, the next Travis config will help you:
I cannot say I am happy with this workaround, but until Travis will update their build packs we can do nothing.
[grizzly] Remove workaround for numpy/numpy#12736
deepsach commentedon Jun 11, 2020
I get this error while import pandas in python
numpy has no Version module
Soul0702 commentedon Nov 21, 2023
(voice-clone) C:\Users\DELL\Desktop\voice>python demo_cli.py
Traceback (most recent call last):
File "C:\Users\DELL\Desktop\voice\demo_cli.py", line 5, in
import librosa
File "C:\Users\DELL\anaconda3\envs\voice-clone\Lib\site-packages\librosa_init_.py", line 211, in
from . import core
File "C:\Users\DELL\anaconda3\envs\voice-clone\Lib\site-packages\librosa\core_init_.py", line 9, in
from .constantq import * # pylint: disable=wildcard-import
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\DELL\anaconda3\envs\voice-clone\Lib\site-packages\librosa\core\constantq.py", line 1058, in
dtype=np.complex,
^^^^^^^^^^
File "C:\Users\DELL\anaconda3\envs\voice-clone\Lib\site-packages\numpy_init_.py", line 324, in getattr
raise AttributeError(former_attrs[attr])
AttributeError: module 'numpy' has no attribute 'complex'.
np.complexwas a deprecated alias for the builtincomplex. To avoid this error in existing code, usecomplexby itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, usenp.complex128here.The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations. Did you mean: 'complex_'?