Numpy: cannot import name '_validate_lengths'

Created on 15 Jan 2019  ·  21Comments  ·  Source: numpy/numpy

it occurs only with numpy 1.16, numpy 1.15 works fine

Using TensorFlow backend.
Traceback (most recent call last):
  File ".\predict.py", line 4, in <module>
    from frontend import YOLO
  File "C:\RepositoriosGit\keras-yolo2\frontend.py", line 8, in <module>
    from preprocessing import BatchGenerator
  File "C:\RepositoriosGit\keras-yolo2\preprocessing.py", line 1, in <module>
    from imgaug import augmenters as iaa
  File "C:\Program Files\Python36\lib\site-packages\imgaug\__init__.py", line 2, in <module>
    from imgaug.imgaug import *
  File "C:\Program Files\Python36\lib\site-packages\imgaug\imgaug.py", line 22, in <module>
    import skimage.draw
  File "C:\Program Files\Python36\lib\site-packages\skimage\__init__.py", line 167, in <module>
    from .util.dtype import (img_as_float32,
  File "C:\Program Files\Python36\lib\site-packages\skimage\util\__init__.py", line 8, in <module>
    from .arraycrop import crop
  File "C:\Program Files\Python36\lib\site-packages\skimage\util\arraycrop.py", line 8, in <module>
    from numpy.lib.arraypad import _validate_lengths
ImportError: cannot import name '_validate_lengths'

Numpy/Python version information:

>>> import sys, numpy; print(numpy.__version__, sys.version)
1.16.0 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)]

Most helpful comment

I have already solved this problem, just use conda install -c conda-forge scikit-image, not pip install -U scikit-image

All 21 comments

Yes, it looks like this disappeared in numpy 1.16.0. But, as you probably noticed, the function has a prepended underscore, meaning that scikit-image was being a bit naughty importing that function.

There's a scikit-image issue here: https://github.com/scikit-image/scikit-image/issues/3649

Closing in favor of that issue.

Thank you @matthew-brett for your quick answer.

Yes, it looks like this disappeared in numpy 1.16.0. But, as you probably noticed, the function has a prepended underscore, meaning that scikit-image was being a bit naughty importing that function.

Correct. To give some context, this function came from scikit-image originally, and was ported to NumPy, and we didn't clean up very well afterwards. I think the pain associated with fixing this will be a vivid reminder not to do this again in the future.

v0.14.2 has been released and addresses the issue.

Hi, have the same problem. Just update all packages.

Successfully installed PyWavelets-1.0.2 backports.functools-lru-cache-1.5 cloudpickle-0.8.0 cycler-0.10.0 dask-1.1.3 decorator-4.3.2 kiwisolver-1.0.1 matplotlib-2.2.4 networkx-2.2 numpy-1.16.2 pillow-5.4.1 pyparsing-2.3.1 python-dateutil-2.8.0 pytz-2018.9 scikit-image-0.14.2 scipy-1.2.1 setuptools-40.8.0 six-1.12.0 subprocess32-3.5.3 toolz-0.9.0

Can anybody help me to solve this problem?

Please report the output of the following:

import skimage
print(skimage.__version__)

I have this

ImportError: cannot import name '_validate_lengths' from 'numpy.lib.arraypad' (/home/liza/anaconda3/lib/python3.7/site-packages/numpy/lib/arraypad.py)

@stefanv would it make sense if he has scikit-image-0.14.2 (in the comment just before yours)?

Sorry, my brain was clearly on holiday.

0.14.2 fixed this problem, so I imagine another version of the library is being imported. But I don't know how to show that, given that the previous comment states the opposite.

I have already solved this problem, just use conda install -c conda-forge scikit-image, not pip install -U scikit-image

I have already solved this problem, just use conda install -c conda-forge scikit-image, not pip install -U scikit-image

That solved it for me

ImportError: cannot import name '_validate_lengths' from 'numpy.lib.arraypad' (C:\Users\basant\Anaconda3\lib\site-packages\numpy\libarraypad.py)

i have this problem anyone please give the solution for this

@pandagre Please ensure that you have the latest version of scikit-image installed. If you still experience problems, open a new issue and we'll try to help.

I have already solved this problem, just use conda install -c conda-forge scikit-image, not pip install -U scikit-image

This works for me, thanks.

I used conda install -c conda-forge scikit-image but the version I got is 0.14.0. I still have the issue of cannot import name '_validate_lengths'

@yexing99 Please try and install the latest version of scikit-image and numpy. That combination is known to work. Otherwise, please open a new issue and help us debug your setup there, providing all version numbers.

# The following worked fine for me
pip install -U scikit-image

Installing collected packages: scikit-image
Found existing installation: scikit-image 0.14.1
Uninstalling scikit-image-0.14.1:
Successfully uninstalled scikit-image-0.14.1
Successfully installed scikit-image-0.15.0

python -c "import skimage"
# No errors, as expected

I have already solved this problem, just use conda install -c conda-forge scikit-image, not pip install -U scikit-image

As conda install is so slow for me, I tried pip install -U scikit-image and it's also work.

pip install -U scikit-image
This worked for me.

Ya same,
pip install -U scikit-image
This worked for me.

Was this page helpful?
0 / 5 - 0 ratings