Skip to content

Attribute Error after installing v1.16.0 because pip is not uninstalling #12736

Closed

Description

@treyenelson

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:

import numpy as np

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]

Activity

  1. charris commented on Jan 14, 2019

    @charris
    Member

    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.

  2. ababushk commented on Jan 14, 2019

    @ababushk

    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)
    
  3. treyenelson commented on Jan 14, 2019

    @treyenelson
    Author

    @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.

  4. kalbermattenm commented on Jan 14, 2019

    @kalbermattenm

    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.

  5. mattip commented on Jan 14, 2019

    @mattip
    Member

    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.

  6. mattip commented on Jan 14, 2019

    @mattip
    Member

    You have a numpy in your image and you pip install another one or do you pip install --upgrade?

  7. changed the title [-]Attribute Error with v1.16.0[/-] [+]Attribute Error after installing v1.16.0[/+] on Jan 14, 2019
  8. kalbermattenm commented on Jan 14, 2019

    @kalbermattenm

    I did a pip install -r ... with an updated requirement file which is automatically updated through greenkeeper.

  9. mattip commented on Jan 14, 2019

    @mattip
    Member

    I am not a pip expert, is pip install -r <file> supposed to call uninstall when it discovers a stale version?

  10. charris commented on Jan 14, 2019

    @charris
    Member

    I suspect this problem is longstanding, but invisible until we added the attribute to ndarray and used it in _methods.py.

  11. charris commented on Jan 14, 2019

    @charris
    Member

    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?

  12. mattip commented on Jan 14, 2019

    @mattip
    Member

    Pip documentation says they uninstall before installing a new version. But maybe the older version is from an apt-get, not pip?

  13. mattip commented on Jan 14, 2019

    @mattip
    Member

    @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

  14. mattip commented on Jan 14, 2019

    @mattip
    Member

    @kalbermattenm, @treyenelson, @oxygenxo: was the old version pip-installed or was it part of some other installation (apt, yum, anaconda, ...)

  15. charris commented on Jan 14, 2019

    @charris
    Member

    @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.

  16. 59 remaining items

  17. dmitriyshashkin commented on Jan 24, 2019

    @dmitriyshashkin

    I also had the same problem with pip from conda

  18. tzickel commented on Jan 24, 2019

    @tzickel

    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.

  19. wenzao commented on Jan 25, 2019

    @wenzao

    I rolled back to v1.15 and it's working now.

  20. tzickel commented on Jan 25, 2019

    @tzickel

    @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).

  21. blondegeek commented on Jan 25, 2019

    @blondegeek

    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.

  22. bwanglzu commented on Jan 28, 2019

    @bwanglzu

    @elliothe thanks you saved my day!

    1. sudo pip3 uninstall numpy
    2. sudo pip3 uninstall numpy
      .... do this until you can not uninstall numpy anymore
    3. sudo pip3 install -U numpy

    ubuntu 18.04, python 3.5.

  23. kellyfj commented on Jan 29, 2019

    @kellyfj

    @elliothe thanks you saved my day!

    1. sudo pip3 uninstall numpy
    2. sudo pip3 uninstall numpy
      .... do this until you can not uninstall numpy anymore
    3. sudo pip3 install -U numpy

    ubuntu 18.04, python 3.5.

    This sequence of successive uninstalls fixed it for me

  24. removed this from the 1.16.1 release milestone on Jan 31, 2019
  25. mattip commented on Mar 6, 2019

    @mattip
    Member

    Closing. We now detect this and emit a better error message.

  26. amureki commented on Mar 13, 2019

    @amureki

    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:

    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.

  27. deepsach commented on Jun 11, 2020

    @deepsach

    IMG-20200605-WA0021
    I get this error while import pandas in python
    numpy has no Version module

  28. Soul0702 commented on Nov 21, 2023

    @Soul0702

    (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_'?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions