在Anaconda下新配置了tensorflow环境,结果在引入skimage 包时报错,错误提示from numpy.lib.arraypad import _validate_lengths,找不到_validate_lengths函数,在arraypad.py文件中确实找不到对应的函数,所以找到以前配置过的环境中对应的文件,拷贝这个缺失的函数,问题解决(****************一定要重启环境)。

(flappbird1) luo@luo-All-Series:~/MyFile/COCO/coco/PythonAPI$
(flappbird1) luo@luo-All-Series:~/MyFile/COCO/coco/PythonAPI$ python\
>
Python 3.7.2 (default, Dec 29 2018, 06:19:36)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>>
>>> from skimage import io
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/luo/anaconda3/envs/flappbird1/lib/python3.7/site-packages/skimage/__init__.py", line 167, in <module>
    from .util.dtype import (img_as_float32,
  File "/home/luo/anaconda3/envs/flappbird1/lib/python3.7/site-packages/skimage/util/__init__.py", line 8, in <module>
    from .arraycrop import crop
  File "/home/luo/anaconda3/envs/flappbird1/lib/python3.7/site-packages/skimage/util/arraycrop.py", line 8, in <module>
    from numpy.lib.arraypad import _validate_lengths
ImportError: cannot import name '_validate_lengths' from 'numpy.lib.arraypad' (/home/luo/anaconda3/envs/flappbird1/lib/python3.7/site-packages/numpy/lib/arraypad.py)
>>>
>>>
>>>
>>>
>>> from skimage import data, io, filters
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/luo/anaconda3/envs/flappbird1/lib/python3.7/site-packages/skimage/__init__.py", line 176, in <module>
    from .util.lookfor import lookfor
  File "/home/luo/anaconda3/envs/flappbird1/lib/python3.7/site-packages/skimage/util/__init__.py", line 8, in <module>
    from .arraycrop import crop
  File "/home/luo/anaconda3/envs/flappbird1/lib/python3.7/site-packages/skimage/util/arraycrop.py", line 8, in <module>
    from numpy.lib.arraypad import _validate_lengths
ImportError: cannot import name '_validate_lengths' from 'numpy.lib.arraypad' (/home/luo/anaconda3/envs/flappbird1/lib/python3.7/site-packages/numpy/lib/arraypad.py)
>>>
>>>
>>>
>>>
>>> from skimage import data, io, filters
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/luo/anaconda3/envs/flappbird1/lib/python3.7/site-packages/skimage/__init__.py", line 176, in <module>
    from .util.lookfor import lookfor
  File "/home/luo/anaconda3/envs/flappbird1/lib/python3.7/site-packages/skimage/util/__init__.py", line 8, in <module>
    from .arraycrop import crop
  File "/home/luo/anaconda3/envs/flappbird1/lib/python3.7/site-packages/skimage/util/arraycrop.py", line 8, in <module>
    from numpy.lib.arraypad import _validate_lengths
ImportError: cannot import name '_validate_lengths' from 'numpy.lib.arraypad' (/home/luo/anaconda3/envs/flappbird1/lib/python3.7/site-packages/numpy/lib/arraypad.py)
>>>
>>>
>>>
>>> from skimage import io
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/luo/anaconda3/envs/flappbird1/lib/python3.7/site-packages/skimage/__init__.py", line 176, in <module>
    from .util.lookfor import lookfor
  File "/home/luo/anaconda3/envs/flappbird1/lib/python3.7/site-packages/skimage/util/__init__.py", line 8, in <module>
    from .arraycrop import crop
  File "/home/luo/anaconda3/envs/flappbird1/lib/python3.7/site-packages/skimage/util/arraycrop.py", line 8, in <module>
    from numpy.lib.arraypad import _validate_lengths
ImportError: cannot import name '_validate_lengths' from 'numpy.lib.arraypad' (/home/luo/anaconda3/envs/flappbird1/lib/python3.7/site-packages/numpy/lib/arraypad.py)
>>>
>>>
>>>
>>> exit()
(flappbird1) luo@luo-All-Series:~/MyFile/COCO/coco/PythonAPI$
(flappbird1) luo@luo-All-Series:~/MyFile/COCO/coco/PythonAPI$

---------------------------------------------------------------------------------------------------

找到:Anaconda3/envs/your dir/lib/python3.7/site-packages/numpy/lib/arraypad.py   954行,添加洗下面两个函数保存,重新加载即可消除错误(****************一定要重启环境)

--------------------------------------------------------------------------------------------------

def _normalize_shape(ndarray, shape, cast_to_int=True):
    """
    Private function which does some checks and normalizes the possibly
    much simpler representations of 'pad_width', 'stat_length',
    'constant_values', 'end_values'.

Parameters
    ----------
    narray : ndarray
        Input ndarray
    shape : {sequence, array_like, float, int}, optional
        The width of padding (pad_width), the number of elements on the
        edge of the narray used for statistics (stat_length), the constant
        value(s) to use when filling padded regions (constant_values), or the
        endpoint target(s) for linear ramps (end_values).
        ((before_1, after_1), ... (before_N, after_N)) unique number of
        elements for each axis where `N` is rank of `narray`.
        ((before, after),) yields same before and after constants for each
        axis.
        (constant,) or val is a shortcut for before = after = constant for
        all axes.
    cast_to_int : bool, optional
        Controls if values in ``shape`` will be rounded and cast to int
        before being returned.

Returns
    -------
    normalized_shape : tuple of tuples
        val                               => ((val, val), (val, val), ...)
        [[val1, val2], [val3, val4], ...] => ((val1, val2), (val3, val4), ...)
        ((val1, val2), (val3, val4), ...) => no change
        [[val1, val2], ]                  => ((val1, val2), (val1, val2), ...)
        ((val1, val2), )                  => ((val1, val2), (val1, val2), ...)
        [[val ,     ], ]                  => ((val, val), (val, val), ...)
        ((val ,     ), )                  => ((val, val), (val, val), ...)

"""
    ndims = ndarray.ndim

# Shortcut shape=None
    if shape is None:
        return ((None, None), ) * ndims

# Convert any input `info` to a NumPy array
    shape_arr = np.asarray(shape)

try:
        shape_arr = np.broadcast_to(shape_arr, (ndims, 2))
    except ValueError:
        fmt = "Unable to create correctly shaped tuple from %s"
        raise ValueError(fmt % (shape,))

# Cast if necessary
    if cast_to_int is True:
        shape_arr = np.round(shape_arr).astype(int)

# Convert list of lists to tuple of tuples
    return tuple(tuple(axis) for axis in shape_arr.tolist())

def _validate_lengths(narray, number_elements):
    """
    Private function which does some checks and reformats pad_width and
    stat_length using _normalize_shape.

Parameters
    ----------
    narray : ndarray
        Input ndarray
    number_elements : {sequence, int}, optional
        The width of padding (pad_width) or the number of elements on the edge
        of the narray used for statistics (stat_length).
        ((before_1, after_1), ... (before_N, after_N)) unique number of
        elements for each axis.
        ((before, after),) yields same before and after constants for each
        axis.
        (constant,) or int is a shortcut for before = after = constant for all
        axes.

Returns
    -------
    _validate_lengths : tuple of tuples
        int                               => ((int, int), (int, int), ...)
        [[int1, int2], [int3, int4], ...] => ((int1, int2), (int3, int4), ...)
        ((int1, int2), (int3, int4), ...) => no change
        [[int1, int2], ]                  => ((int1, int2), (int1, int2), ...)
        ((int1, int2), )                  => ((int1, int2), (int1, int2), ...)
        [[int ,     ], ]                  => ((int, int), (int, int), ...)
        ((int ,     ), )                  => ((int, int), (int, int), ...)

"""
    normshp = _normalize_shape(narray, number_elements)
    for i in normshp:
        chk = [1 if x is None else x for x in i]
        chk = [1 if x >= 0 else -1 for x in chk]
        if (chk[0] < 0) or (chk[1] < 0):
            fmt = "%s cannot contain negative values."
            raise ValueError(fmt % (number_elements,))
    return normshp

###############################################################################
# Public functions

cannot import name '_validate_lengths' from 'numpy.lib.arraypad'的更多相关文章

  1. [Python] Array Attributes of Numpy lib

    Attributes of numpy.ndarray: numpy.ndarray.shape: Dimensions (height, width, ...) numpy.ndarray.ndim ...

  2. [Python] Generating random numbers using numpy lib

    import numpy as np def test_run(): data=np.random.random((3,4)) """ [[ 0.80150549 0.9 ...

  3. when i import skimage,it occurred --"cannot import name '_validate_lengths'"

    how to sovle this prolem? 1)with the administrator user to run cmd 2)imput and run : pip install --u ...

  4. 【400】numpy.pad 为数组加垫(迷宫类题目)

    参考:Numpy学习——数组填充np.pad()函数的应用 举例说明: import numpy as np a = np.zeros((3, 4), dtype=int) a array([[0, ...

  5. scipy几乎实现numpy的所有函数

    NumPy和SciPy的关系?   numpy提供了数组对象,面向的任何使用者.scipy在numpy的基础上,面向科学家和工程师,提供了更为精准和广泛的函数.scipy几乎实现numpy的所有函数, ...

  6. 【pytorch】持续踩坑 & 错误解决经历

    报错 1.[invalid argument 0: Sizes of tensors must match except in dimension 0.] {出现在 torch.utils.data. ...

  7. ImportError: numpy.core.multiarray failed to import

    1. ImportError: numpy.core.multiarray failed to import pip install -U numpy http://stackoverflow.com ...

  8. 安装numpy+mkl

    引子: 运行from sklearn.dataset import load_iris 时提示: Traceback (most recent call last): File "F:/gi ...

  9. gcc, numpy, rabbitmq等安装升级总结

    1. 公司在下面目录安装了gcc-4.8.2,以支持c++11,可以通过在bashrc中添加来实现: PATH=/opt/compiler/gcc-4.8.2/bin:$PATH 2. 公司环境切换到 ...

随机推荐

  1. 移动端固定头部和固定左边第一列的实现方案(Vue中实现demo)

    最近移动端做一份报表,需要左右滚动时,固定左边部分:上下滚动时,固定头部部分. 代码在Vue中简单实现 主要思路是: a.左边部分滚动,实时修改右边部分的滚动条高度 b.头部和内容部分都设置固定高度, ...

  2. C# 中的委托和事件(2)

    委托.事件与Observer设计模式范例说明 上面的例子已不足以再进行下面的讲解了,我们来看一个新的范例,因为之前已经介绍了很多的内容,所以本节的进度会稍微快一些: 假设我们有个高档的热水器,我们给它 ...

  3. 《Hadoop技术内幕》读书笔记——Task运行过程分析

    本文是董西成的Hadoop技术内幕一书的读书章节总结. 第八章 Task运行过程分析 所有Task需要周期性地向TaskTracker汇报最新进度和计数器值,而这正是由Reporter组件实现的,其中 ...

  4. 第一章 先把Kubernetes跑起来

    1.1 先跑起来 k8s官网已经为大家准备好了一个现成的最小可用系统.  https://kubernetes.io/docs/tutorials/kubernetes-basics/ 1.2 创建K ...

  5. python学习(二十三) String(下) 分片和索引

    分片: 记住, 是开闭区间. a = "abcdef"print(a[:])print(a[1:])print(a[:3])print(a[-2])print(a[:-2])pri ...

  6. css 定位position总结

    在CSS中,Position 属性经常会用到,主要是绝对定位和相对定位,简单的使用都没有问题,尤其嵌套起来,就会有些混乱,今记录总结一下,防止久而忘之. CSS position 属性值: absol ...

  7. JAVA构造函数在超类与子类定义鲁波总结

    1.子类无构造函数,超类无构造函数,创建的无参数的对象: 编译通过. class A { } class B extends A { } public class Testeeer { public ...

  8. Linux tar命令高级用法——备份数据

    Linux tar命令高级用法——备份数据 2015-12-31 Linux学习 Linux上有功能强大的tar命令,tar最初是为了制作磁带备份(tape archive)而设计的,它的作用是把文件 ...

  9. Julia - 浮点型

    浮点数类型: Float64 类型,双精度,64 位 Float32 类型,单精度,32 位 Float16 类型,半精度,16 位 julia> 5.0 5.0 julia> 5. 5. ...

  10. 弗雷塞斯 从生物学到生物信息学到机器学习 转录组入门(3):了解fastq测序数据

    sra文件转换为fastq格式 1 fastq-dump -h --split-3 也就是说如果SRA文件中只有一个文件,那么这个参数就会被忽略.如果原文件中有两个文件,那么它就会把成对的文件按*_1 ...