[英]py2exe with import pyfits cause error
When do py2exe in py-file with import pyfits, it caused an error. 当使用导入pyfits在py文件中执行py2exe时,会导致错误。
How to avoid this error? 如何避免这个错误?
I prepare test.py and test_setup.py(for py2exe), which are shown below. 我准备了test.py和test_setup.py(用于py2exe),如下所示。
test.py is simple program to show data of fitsfile specified by the argument. test.py是一个简单的程序,用于显示参数指定的fitsfile数据。
on cmd.exe: 在cmd.exe上:
\python test_setup.py py2exe
=> success =>成功
\python test.py test.fits
[[[574 574 579 ..., 579 585 581]
[574 582 583 ..., 582 579 577]
[581 583 578 ..., 572 580 580]
...,
[584 585 580 ..., 584 582 579]
[585 583 582 ..., 586 575 578]
[584 580 583 ..., 585 585 589]]]
=> success =>成功
\dist\test.exe test.fits
Traceback (most recent call last):
File "test.py", line 4, in <module>
import pyfits
File "pyfits\__init__.pyo", line 11, in <module>
File "pyfits\core.pyo", line 42, in <module>
File "pyfits\convenience.pyo", line 62, in <module>
File "pyfits\hdu\__init__.pyo", line 2, in <module>
File "pyfits\hdu\compressed.pyo", line 21, in <module>
File "pyfits\hdu\table.pyo", line 646, in <module>
File "pyfits\hdu\table.pyo", line 909, in BinTableHDU
TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'
=> error =>错误
test.py test.py
# -*- coding: utf-8 -*-
import sys
import pyfits
def showfits(path):
hdulist = pyfits.open(path)
imgs = hdulist[0].data
hdulist.close()
print imgs
if __name__ == "__main__":
showfits(sys.argv[1])
test_setup.py test_setup.py
# -*- coding: utf-8 -*-
from distutils.core import setup
import py2exe
option = {
"compressed" : 1 ,
"optimize" : 2 ,
"bundle_files" : 3
}
setup(
options = {
"py2exe" : option
},
console = [
{
"script" : "test.py"
}
],
zipfile = None
)
Looking at the line it's crashing on : 看这行崩溃了 :
dump.__doc__ += _tdump_file_format.replace('\n', '\n ')
it seems that pyfits is doing some class-level docstring manipulation. 似乎pyfits正在做一些类级别的docstring操作。 This could reasonably be considered a bug, since it can't always be assumed that a method's
__doc__
will be a string, as in in the case of using optimized compilation (as you are) which, among other things, strips out all docstrings. 这可以合理地认为是一个错误,因为不能总是假定方法的
__doc__
将是一个字符串,例如在使用优化编译的情况下(如您所愿),它可以去除所有docstring。
I think the simplest workarounds would be either to disable optimization, at least for now, or patch pyfits to remove that line and any similar to it. 我认为最简单的解决方法是至少到现在为止禁用优化,或者修补pyfits以删除该行及其类似内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.