gpt4 book ai didi

python - 文件 "E:\python\lib\re.py",第 229 行,在 finditer 中返回 _compile(pattern, flags).finditer(string) TypeError : expected string or bytes-like object

转载 作者:太空宇宙 更新时间:2023-11-04 09:39:21 25 4
gpt4 key购买 nike

我正在使用 skimage.feature.greycomatrix 来计算图像的 GLCM(灰度共现矩阵),但是当我使用时:

from skimage.feature import greycomatrix 

python 3.6.4 shell 中 - 它可以工作。 See image

但是当我在我的 sublime Text 3 中使用它时,那么会报错:

Traceback (most recent call last):
File "C:\Users\Martin Ma\Desktop\every day python\test\GLCM\main.py", line 80, in <module>
from skimage.feature import greycomatrix
File "E:\python\lib\site-packages\skimage\feature\__init__.py", line 9, in <module>
from .peak import peak_local_max
File "E:\python\lib\site-packages\skimage\feature\peak.py", line 3, in <module>
from ..segmentation import relabel_sequential
File "E:\python\lib\site-packages\skimage\segmentation\__init__.py", line 1, in <module>
from .random_walker_segmentation import random_walker
File "E:\python\lib\site-packages\skimage\segmentation\random_walker_segmentation.py", line 43, in <module>
from ..filters import rank_order
File "E:\python\lib\site-packages\skimage\filters\__init__.py", line 3, in <module>
from .edges import (sobel, sobel_h, sobel_v,
File "E:\python\lib\site-packages\skimage\filters\edges.py", line 17, in <module>
from ..restoration.uft import laplacian
File "E:\python\lib\site-packages\skimage\restoration\__init__.py", line 12, in <module>
from .inpaint import inpaint_biharmonic
File "E:\python\lib\site-packages\skimage\restoration\inpaint.py", line 9, in <module>
from ..measure import label
File "E:\python\lib\site-packages\skimage\measure\__init__.py", line 6, in <module>
from ._regionprops import regionprops, perimeter
File "E:\python\lib\site-packages\skimage\measure\_regionprops.py", line 645, in <module>
_install_properties_docs()
File "E:\python\lib\site-packages\skimage\measure\_regionprops.py", line 632, in _install_properties_docs
prop_doc = _parse_docs()
File "E:\python\lib\site-packages\skimage\measure\_regionprops.py", line 625, in _parse_docs
doc, flags=re.DOTALL)
File "E:\python\lib\re.py", line 229, in finditer
return _compile(pattern, flags).finditer(string)
TypeError: expected string or bytes-like object

(See picture of Sublime Text error)

谁能告诉我为什么会这样,我该如何解决?

我的代码:

from skimage.feature import greycomatrix
import numpy as np

image=np.array([[1,1,5,6,8],
[0,0,5,7,1],
[4,0,0,1,2],
[8,5,1,2,5]],dtype=np.uint8)
#levels=256 image this test is 9
result=greycomatrix(image,[1],[0,np.pi/4,np.pi/2,3*np.pi/4],levels=9)
print(result[:, :, 0, 0])

enter image description here

最佳答案

您正在使用 -OO 运行 Python标志,丢弃文档字符串,用 None 替换它们。 skimage.measure._regionprops includes code在初始化期间,解析一个函数的文档字符串以设置一堆其他函数的文档字符串。当文档字符串被丢弃时,这会失败。在没有 -OO 标志的情况下运行 Python 可以避免这个问题。

看起来在 scikit-image 代码库的其他部分可能遇到并修复了类似的问题;我看到一些地方已经检查是否将文档字符串设置为 None,例如 skimage.io .要使 skimage.measure._regionprops-OO 兼容,必须向该模块添加对 None 文档字符串的类似检查。不过,_install_properties_docs 做的不仅仅是文档字符串处理,所以如果我们没有文档字符串,我们不能跳过整个过程。

关于python - 文件 "E:\python\lib\re.py",第 229 行,在 finditer 中返回 _compile(pattern, flags).finditer(string) TypeError : expected string or bytes-like object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52242859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com