【问题标题】:When using Flask with python 3 and SimpleITK 0.10.0 together, i am getting AttributeError: type object 'object' has no attribute '__getattr__'将 Flask 与 python 3 和 SimpleITK 0.10.0 一起使用时,我得到 AttributeError: type object 'object' has no attribute '__getattr__'
【发布时间】:2016-10-05 22:17:19
【问题描述】:

当我在 Python 3 (https://itk.org/SimpleITKDoxygen010/html/Python_2DicomModifyTags_8py-example.html) 中使用 SimpleITK 0.10.0 运行 DCM 文件中更新标签的代码时,代码按说明工作。

当我在代码中引入烧瓶组件来创建 API 时,我得到了

AttributeError: type object 'object' 没有属性 '__getattr__'

错误。我使用的代码如下

from __future__ import print_function
import SimpleITK
from flask import Flask
import time

app = Flask(__name__)


@app.route('/fuse')
def fuse():
    image = SimpleITK.ReadImage("CT/IMG-0002-000001.dcm")

    mean_image = SimpleITK.BoxMean( image, [3,3,1])

    all_keys = image.GetMetaDataKeys()
    for key in all_keys:
        mean_image.SetMetaData(key, image.GetMetaData(key))
    mean_image.SetMetaData("0008|0008", "DERIVED\SECONDARY")
    modification_time = time.strftime("%H%M%S")
    modification_date = time.strftime("%Y%m%d")
    mean_image.SetMetaData("0008|0031", modification_time)
    mean_image.SetMetaData("0008|0021", modification_date)

    print(mean_image.GetMetaData("0008|0031"))
    return "finish"

我得到的错误如下

[2016-10-05 14:47:05,816] ERROR in app: Exception on /fuse [GET]
Traceback (most recent call last):
  File "c:\python27\lib\site-packages\flask\app.py", line 1988, in wsgi_app
    response = self.full_dispatch_request()
  File "c:\python27\lib\site-packages\flask\app.py", line 1641, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "c:\python27\lib\site-packages\flask\app.py", line 1544, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "c:\python27\lib\site-packages\flask\app.py", line 1639, in full_dispatch_request
    rv = self.dispatch_request()
  File "c:\python27\lib\site-packages\flask\app.py", line 1625, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "E:\ITK_EXP_10\exp2.py", line 24, in fuse
    keyable(mean_image, image, key)
  File "E:\ITK_EXP_10\exp2.py", line 12, in keyable
    mean_image.SetMetaData(key, image.GetMetaData(key))
  File "c:\python27\lib\site-packages\SimpleITK\SimpleITK.py", line 3579, in <lambda>
    __getattr__ = lambda self, name: _swig_getattr(self, Image, name)
  File "c:\python27\lib\site-packages\SimpleITK\SimpleITK.py", line 74, in _swig_getattr
    return _swig_getattr_nondynamic(self, class_type, name, 0)
  File "c:\python27\lib\site-packages\SimpleITK\SimpleITK.py", line 69, in _swig_getattr_nondynamic
    return object.__getattr__(self, name)
AttributeError: type object 'object' has no attribute '__getattr__'
127.0.0.1 - - [05/Oct/2016 14:47:05] "GET /fuse HTTP/1.1" 500 -
127.0.0.1 - - [05/Oct/2016 14:47:05] "GET /favicon.ico HTTP/1.1" 404 -

我是python编码的初学者,实际上是编码本身的初学者,有人可以帮我解决这个问题,或者帮助我理解这个问题以便我解决它吗?

提前致谢

【问题讨论】:

    标签: python-3.x flask flask-restful


    【解决方案1】:

    问题是因为在 pycharm 和终端中运行的 python 版本不同。终端运行的是 2.7,pycharm 是 3.5。该库在 3.5 中更新。很抱歉造成混乱

    【讨论】:

      猜你喜欢
      • 2023-01-22
      • 2022-12-27
      • 1970-01-01
      • 2019-12-08
      • 2020-06-17
      • 2014-05-18
      • 2022-12-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多