When using Flask with python 3 and SimpleITK 0.10.0 together, i am getting AttributeError: type object 'object' has no attribute '__getattr__'
When using Flask with python 3 and SimpleITK 0.10.0 together, i am getting AttributeError: type object 'object' has no attribute '__getattr__'
当我 运行 在 Python 3 (https://itk.org/SimpleITKDoxygen010/html/Python_2DicomModifyTags_8py-example.html) 中使用 SimpleITK 0.10.0 更新 DCM 文件中标签的代码时,代码按说明工作。
当我在代码中引入烧瓶组件来创建 API 时,我得到
AttributeError: 类型对象 '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 编码的初学者,实际上是编码本身的初学者,有人可以帮我解决这个问题,或者帮助我理解这个问题以便我可以解决它吗?
提前致谢
问题是因为 pycharm 和终端中的 python 运行 版本不同。终端是 运行 2.7,pycharm 是 3.5。该库已在 3.5 中更新。抱歉造成混淆
当我 运行 在 Python 3 (https://itk.org/SimpleITKDoxygen010/html/Python_2DicomModifyTags_8py-example.html) 中使用 SimpleITK 0.10.0 更新 DCM 文件中标签的代码时,代码按说明工作。
当我在代码中引入烧瓶组件来创建 API 时,我得到
AttributeError: 类型对象 '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 编码的初学者,实际上是编码本身的初学者,有人可以帮我解决这个问题,或者帮助我理解这个问题以便我可以解决它吗?
提前致谢
问题是因为 pycharm 和终端中的 python 运行 版本不同。终端是 运行 2.7,pycharm 是 3.5。该库已在 3.5 中更新。抱歉造成混淆