编译后Python Py2exe错误

时间:2015-06-10 23:54:57

标签: python-3.x py2exe

我写的一个非常复杂的应用程序集成了很多模块。 Matplotlib给出了一些错误,直到我明确地将它包含在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'

1 个答案:

答案 0 :(得分:0)

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

我使用的解决方法是在我的脚本中声明:

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

另外,我将以下内容添加到我的py2exe的setup.py文件中

"packages":["pkg_resources"],

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

  

如果您对默认单位进行翻译或定义一个全新的集合,则不希望附加已翻译的定义,因此您只需将文件名提供给构造函数:

     
    
      

来自pint import UnitRegistry       ureg = UnitRegistry('/ your / path / to / default_es.txt')

    
  

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

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

相关问题