运行以下语句:from skimage import transform
出现如题所示错误,出现错误是因为
C:\Users\Anaconda3\Lib\site-packages\skimage\util
这个文件中的第八行代码要从arraypad.py中导入一个名为_validate_lengths的函数,而系统在该文件中找不到该函数,出现这个错误可能是因为numpy版本升级导致的,但不建议降低numpy版本。解决办法如下:

第一步:

在C:\Users\Anaconda3\Lib\site-packages\skimage\util目录中找到arraycrop.py,并打开,该文件中已经给出了因为numpy版本变化导致arraycrop不可用的方法,即将以注释方式给出的两个函数复制到
C:\Users\Anaconda3\Lib\site-packages\numpy\lib目录中找到arraypad.py文件中。相关注释如下所示:

# The below functions are retained in comments in case the NumPy architecture
# changes and we need copies of these helper functions for `crop`.
# These are identical to functions in numpy.lib.arraypad.py as of NumPy v1.11# 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
#     arr = np.asarray(shape)
#
#     # Switch based on what input looks like
#     if arr.ndim <= 1:
#         if arr.shape == () or arr.shape == (1,):
#             # Single scalar input
#             #   Create new array of ones, multiply by the scalar
#             arr = np.ones((ndims, 2), dtype=ndarray.dtype) * arr
#         elif arr.shape == (2,):
#             # Apply padding (before, after) each axis
#             #   Create new axis 0, repeat along it for every axis
#             arr = arr[np.newaxis, :].repeat(ndims, axis=0)
#         else:
#             fmt = "Unable to create correctly shaped tuple from %s"
#             raise ValueError(fmt % (shape,))
#
#     elif arr.ndim == 2:
#         if arr.shape[1] == 1 and arr.shape[0] == ndims:
#             # Padded before and after by the same amount
#             arr = arr.repeat(2, axis=1)
#         elif arr.shape[0] == ndims:
#             # Input correctly formatted, pass it on as `arr`
#             arr = shape
#         else:
#             fmt = "Unable to create correctly shaped tuple from %s"
#             raise ValueError(fmt % (shape,))
#
#     else:
#         fmt = "Unable to create correctly shaped tuple from %s"
#         raise ValueError(fmt % (shape,))
#
#     # Cast if necessary
#     if cast_to_int is True:
#         arr = np.round(arr).astype(int)
#
#     # Convert list of lists to tuple of tuples
#     return tuple(tuple(axis) for axis in 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

第二步:

在C:\Users\Anaconda3\Lib\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 possiblymuch simpler representations of 'pad_width', 'stat_length','constant_values', 'end_values'.Parameters----------narray : ndarrayInput ndarrayshape : {sequence, array_like, float, int}, optionalThe width of padding (pad_width), the number of elements on theedge of the narray used for statistics (stat_length), the constantvalue(s) to use when filling padded regions (constant_values), or theendpoint target(s) for linear ramps (end_values).((before_1, after_1), ... (before_N, after_N)) unique number ofelements for each axis where `N` is rank of `narray`.((before, after),) yields same before and after constants for eachaxis.(constant,) or val is a shortcut for before = after = constant forall axes.cast_to_int : bool, optionalControls if values in ``shape`` will be rounded and cast to intbefore being returned.Returns-------normalized_shape : tuple of tuplesval                               => ((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=Noneif shape is None:return ((None, None), ) * ndims# Convert any input `info` to a NumPy arrayshape_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 necessaryif cast_to_int is True:shape_arr = np.round(shape_arr).astype(int)# Convert list of lists to tuple of tuplesreturn 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 andstat_length using _normalize_shape.Parameters----------narray : ndarrayInput ndarraynumber_elements : {sequence, int}, optionalThe width of padding (pad_width) or the number of elements on the edgeof the narray used for statistics (stat_length).((before_1, after_1), ... (before_N, after_N)) unique number ofelements for each axis.((before, after),) yields same before and after constants for eachaxis.(constant,) or int is a shortcut for before = after = constant for allaxes.Returns-------_validate_lengths : tuple of tuplesint                               => ((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

保存后,重启该环境对应的kernel,注意一定不要忘了重启!!!

完美解决cannot import name ‘_validate_lengths‘ from ‘numpy.lib.arraypad‘错误相关推荐

  1. [bug解决] cannot import name ‘_validate_lengths‘ from ‘numpy.lib.arraypad‘

    文章目录 问题描述: 原因分析: 解决方案: 方案1(不推荐): 方案2(推荐): 解决步骤: 可能遇到的报错 问题描述: skimage 报错 from skimage import io 报错信息 ...

  2. ImportError: cannot import name ‘_validate_lengths‘ from ‘numpy.lib.arraypad‘完美解决方法

    报错原因 numpy版本与skimage版本不匹配 解决方法 打开Anaconda3的arraycrop.py,该文件我是在这里的C:\ProgramData\Anaconda3\Lib\site-p ...

  3. scikit-image安装 from numpy.lib.arraypad import _validate_lengths ImportError: cannot import name ‘_va

    [写在前面]提示没有skimage.io 安装界面如下 [报错] from numpy.lib.arraypad import _validate_lengths ImportError: canno ...

  4. 完美解决SyntaxError: import * only allowed at module level

    完美解决SyntaxError: import * only allowed at module level 文章目录 报错问题 解决方法 PS 报错问题 之前在工作中遇到过这个坑,记录一下问题以及解 ...

  5. 完美解决安装MySQL Install/Remove of the Service Denied!错误解决办法

    在cmd.exe 控制界面卸载MySQL,结果报错信息如下: Install/Remove of the Service Denied! 原来我用win+R进入的竟然不是admin身份(系统管理员,最 ...

  6. 解决“ImportError: cannot import name ‘_validate_lengths‘”问题

    问题描述 在运行程序的时候报错: Traceback (most recent call last):File "demo_heat_map.py", line 2, in < ...

  7. 运行tensorflow程序,出现ImportError: cannot import name '_validate_lengths'错误的解决办法

    运行tensorflow程序,出现ImportError: cannot import name '_validate_lengths'错误的解决办法 如下图: 原因 问题原因:这是skimage版本 ...

  8. 完美解决:调用sklearn出现诸如ImportError: cannot import name ‘LogisticR‘ from ‘sklearn.linear_model‘ (D:\Progr

    1.问题:调用sklearn出现诸如 ImportError: cannot import name 'LogisticR' from 'sklearn.linear_model' (D:\Progr ...

  9. matplotlib.pyplot常用画图方式函数封装(一)——.plot绘制折线图及设置坐标轴箭头完美解决

    matplotlib.pyplot常用画图方式函数封装(一)--.plot绘制折线图及设置坐标轴箭头完美解决 py.plot常见绘图设置函数封装 绘制函数图像(完美解决坐标轴添加箭头) 绘制折线图 p ...

  10. android 置灰不可点击,Android Studio 运行按钮灰色的完美解决方法

    Android Studio 运行按钮灰色的完美解决方法 今天新建项目的时候突然发现编译后运行按钮为灰色. 解决方案:第一步:点击图中的Add Configuration,出来如下界面 第二步:点+号 ...

最新文章

  1. ICANN敦促业界使用DNSSEC,应对DNS劫持攻击
  2. hdu4862 费用流(不错)
  3. ShopXO本地化部署安装之centeros 安装Apache2.4.6 + PHP7.0.33 + Mysql5.7.25环境
  4. Moodle安装步骤
  5. Cocos2d-x游戏开发之lua编辑器 Sublime 搭建,集成cocos2dLuaApi和自有类
  6. php数组的用法,PHP array_udiff_uassoc() 函数
  7. springboot 实现机器学习_SpringBoot架构浅谈
  8. Galera Cluster大坑的解决方案
  9. 弹簧管压力表设计报告
  10. Vue播放m3u8视频格式的视频监控(适合移动端和pc端),用了Video.js,以及多视频列表循环播放代码,已测试,可播放
  11. Minecraft MOD 开发记录
  12. 深入理解B/S与C/S架构
  13. C#语言实例源码系列-实现Linq操作Xml
  14. 就是美女,怎么了!!!
  15. android 清理系统缓存文件怎么恢复,文件过期或已被清理怎么恢复(微信如何恢复已清理文件)...
  16. ios 判断手机角度_IOS 判断iPhone刘海屏
  17. android 布局 缩小图片大小,三大布局的基本摆放属性总结,以及imageVIew图片摆放的缩放问题...
  18. 密码子偏好性分析~codonW,EMBOSS:CUSP(图文教程)
  19. _stdcall和_cdec区别
  20. ffmpeg解析视频的每一帧(java )

热门文章

  1. java海贼王秘宝传说下载_海贼王秘宝传说攻略 星月岛任务详解一览
  2. windows下快速安装nginx并配置开机自启动的方法
  3. 增长率用计算机怎么算,增长率计算公式(excel公式来计算平均增长率的方法)...
  4. 计算机考研方向哪个好考,2022考研:计算机专业考研选择哪个方向比较好就业?...
  5. 读取视频文件python-opencv
  6. java多线程视频转码_java 后台视频转码、压缩工具
  7. Go语言开发第1课-环境搭建及简单程序入门
  8. 下面哪个不是python合法的变量名_下面哪个不是Python合法的标识符
  9. @RequestBody注解的简单用法
  10. php 云片网对接,云片网络短信发送 PHP SDK 奉上