2015-06-10 81 views
1

我写了一个非常复杂的应用程序,它集成了很多模块。 Matplotlib提供了一些错误,直到我明确将它包含在py2exe文件中。我编译并尝试启动程序后出现此错误,我不明白它的含义。任何帮助感谢!编译后Python Py2exe错误

Py2exe编译文件:

from distutils.core import setup 
import py2exe, sys, os 
sys.argv.append('py2exe') 

setup(
    options = { 
     'py2exe': { 
      'optimize': 2, 
      'includes' : ["matplotlib.backends.backend_tkagg"], 
      'packages' : ['matplotlib', 'pytz'], 
     } 
    }, 
    windows = [{'script': "MYAPP.py", "icon_resources": [(1, "s.ico")]}], 
    zipfile = "shared.lib", 

错误编译后启动时:

Traceback (most recent call last): 
    File "C:\Python34\lib\site-packages\pint\unit.py", line 756, in load_definitions 
    with closing(pkg_resources.resource_stream(__name__, file)) as fp: 
    File "C:\Python34\lib\site-packages\pkg_resources\__init__.py", line 1167, in resource_stream 
    self, resource_name 
    File "C:\Python34\lib\site-packages\pkg_resources\__init__.py", line 1602, in get_resource_stream 
    return io.BytesIO(self.get_resource_string(manager, resource_name)) 
    File "C:\Python34\lib\site-packages\pkg_resources\__init__.py", line 1605, in get_resource_string 
    return self._get(self._fn(self.module_path, resource_name)) 
    File "C:\Python34\lib\site-packages\pkg_resources\__init__.py", line 1683, in _get 
    return self.loader.get_data(path) 
OSError: [Errno 0] Error: 'pint\\default_en.txt' 
+0

你是如何在cmd中设置的,例如setup.py py2exe? – Shaggy89

+0

我正在直接运行上面的py2exe.py文件。它适用于其他程序。有一些模块搞砸了。 – rankind

回答

0

我觉得这里的问题在于py2exe的处理txt文件。它看起来像你使用的品脱模块,而在品脱是文件default_en.txt(你的编译应用程序抱怨)。当py2exe编译pint时,它会忽略包含在pint包中的txt文件。

我所用的解决方法是状态我的脚本中:

ureg = pint.UnitRegistry('\path\to\default_en.txt') 

还,我说从下面到我的setup.py文件的py2exe

"packages":["pkg_resources"], 

http://pint.readthedocs.org/en/0.6/index.html

如果您对默认单位进行了翻译或定义了一个全新的集合,则不需要将翻译定义,所以你只需要给文件名的构造:

从品脱进口UnitRegistry ureg = UnitRegistry( '/你/路径/到/ default_es.txt')

我在我的项目中创建了一个位置\path\to\,并将default_en.txtconstants_en.txt添加到该文件夹​​(从pint文件夹复制)。然后在py2exe中,我将这些文件添加到了我的data_files中。

真正的解决办法是弄清楚如何让py2exe在模块文件夹中包含txt文件,但我还没有弄清楚。