cannot import name '_validate_lengths' from 'numpy.lib.arraypad'
在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'的更多相关文章
- [Python] Array Attributes of Numpy lib
Attributes of numpy.ndarray: numpy.ndarray.shape: Dimensions (height, width, ...) numpy.ndarray.ndim ...
- [Python] Generating random numbers using numpy lib
import numpy as np def test_run(): data=np.random.random((3,4)) """ [[ 0.80150549 0.9 ...
- 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 ...
- 【400】numpy.pad 为数组加垫(迷宫类题目)
参考:Numpy学习——数组填充np.pad()函数的应用 举例说明: import numpy as np a = np.zeros((3, 4), dtype=int) a array([[0, ...
- scipy几乎实现numpy的所有函数
NumPy和SciPy的关系? numpy提供了数组对象,面向的任何使用者.scipy在numpy的基础上,面向科学家和工程师,提供了更为精准和广泛的函数.scipy几乎实现numpy的所有函数, ...
- 【pytorch】持续踩坑 & 错误解决经历
报错 1.[invalid argument 0: Sizes of tensors must match except in dimension 0.] {出现在 torch.utils.data. ...
- ImportError: numpy.core.multiarray failed to import
1. ImportError: numpy.core.multiarray failed to import pip install -U numpy http://stackoverflow.com ...
- 安装numpy+mkl
引子: 运行from sklearn.dataset import load_iris 时提示: Traceback (most recent call last): File "F:/gi ...
- gcc, numpy, rabbitmq等安装升级总结
1. 公司在下面目录安装了gcc-4.8.2,以支持c++11,可以通过在bashrc中添加来实现: PATH=/opt/compiler/gcc-4.8.2/bin:$PATH 2. 公司环境切换到 ...
随机推荐
- yum命令集
升级相关命令: yum update : 安装所有更新软件 yum update xxx : 仅更新指定的软件 yum check-update : 列出所有可更新的软件清单 yum list : 列 ...
- 函数参数个数不确定时使用va_start
今天在网上看程序时忽然发现别人的函数参数中有省略号,甚是吃惊,发现其函数中使用了va_start,经过查资料大概明白其用法,个人觉得很好用! #include <stdio.h> #inc ...
- 你一定想知道的关于FPGA的那些事
首先,如果您从未接触过FPGA(现场可编程门阵列),或者有过一点基础想要继续深入了解这个行业,在这里,会向您介绍FPGA,并且向您解释FPGA都能解决什么问题,如何解决这些问题,并讨论如何将设计进行优 ...
- python--logging库学习_第二波
用Python写代码的时候,在想看的地方写个print xx 就能在控制台上显示打印信息,这样子就能知道它是什么了,但是当我需要看大量的地方或者在一个文件中查看的时候,这时候print就不大方便了,所 ...
- java代码FileInputStream的复制粘贴练习
所有的输入输出流都是对于程序来说的,这个图是实现文件内容的复制粘贴功能的e 首先把文件读到哦程序里,然后把程序读出到文件l package com.a.b; //这个复制和粘贴-----------首 ...
- [转]Jsp 页面中的错误
1. Jsp 语法格式问题,导致其不能被翻译成 Servlet 源文件. 2. Jsp 翻译成 Servlet 源文件后出现的语法格式问题. 3. Jsp 翻译成 Servlet 后运行时发生异常.
- Oracle通过JDBC插入数据时,自增ID如何自动增长
一.通过触发器的方式 CREATE OR REPLACE TRIGGER tg_test BEFORE INSERT ON Userinfo FOR EACH ROW WHEN (new.userNo ...
- 使用exe4j把java程序生成可执行的.exe文件
exe4j可以很容易把一个jar打成exe. 下载地址:http://dl.dbank.com/c0owlopqf8 1.下载的安装文件,里面包含一个注册码生成的工具 2.安装exe4j以及破解(注 ...
- 【洛谷】P1892 团伙(并查集)+ 求助
题目描述 1920年的芝加哥,出现了一群强盗.如果两个强盗遇上了,那么他们要么是朋友,要么是敌人.而且有一点是肯定的,就是: 我朋友的朋友是我的朋友: 我敌人的敌人也是我的朋友. 两个强盗是同一团伙的 ...
- MySql入门(1)
环境变量的重要性环境变量是在操作系统中一个具有特定名字的对象,它包含了一个或者多个应用程序所将使用到的信息.例如Windows和DOS操作系统中的path环境变量,当要求系统运行一个程序而没有告诉它程 ...