• <bdo id='G6dXw'></bdo><ul id='G6dXw'></ul>
    1. <legend id='G6dXw'><style id='G6dXw'><dir id='G6dXw'><q id='G6dXw'></q></dir></style></legend>

      <i id='G6dXw'><tr id='G6dXw'><dt id='G6dXw'><q id='G6dXw'><span id='G6dXw'><b id='G6dXw'><form id='G6dXw'><ins id='G6dXw'></ins><ul id='G6dXw'></ul><sub id='G6dXw'></sub></form><legend id='G6dXw'></legend><bdo id='G6dXw'><pre id='G6dXw'><center id='G6dXw'></center></pre></bdo></b><th id='G6dXw'></th></span></q></dt></tr></i><div id='G6dXw'><tfoot id='G6dXw'></tfoot><dl id='G6dXw'><fieldset id='G6dXw'></fieldset></dl></div>

        <small id='G6dXw'></small><noframes id='G6dXw'>

        <tfoot id='G6dXw'></tfoot>
      1. matplotlib 数据的 cx_freeze 错误

        cx_freeze error with matplotlib data(matplotlib 数据的 cx_freeze 错误)
        <legend id='L0Xyb'><style id='L0Xyb'><dir id='L0Xyb'><q id='L0Xyb'></q></dir></style></legend>
          • <bdo id='L0Xyb'></bdo><ul id='L0Xyb'></ul>
            <i id='L0Xyb'><tr id='L0Xyb'><dt id='L0Xyb'><q id='L0Xyb'><span id='L0Xyb'><b id='L0Xyb'><form id='L0Xyb'><ins id='L0Xyb'></ins><ul id='L0Xyb'></ul><sub id='L0Xyb'></sub></form><legend id='L0Xyb'></legend><bdo id='L0Xyb'><pre id='L0Xyb'><center id='L0Xyb'></center></pre></bdo></b><th id='L0Xyb'></th></span></q></dt></tr></i><div id='L0Xyb'><tfoot id='L0Xyb'></tfoot><dl id='L0Xyb'><fieldset id='L0Xyb'></fieldset></dl></div>

            <small id='L0Xyb'></small><noframes id='L0Xyb'>

                <tbody id='L0Xyb'></tbody>
            1. <tfoot id='L0Xyb'></tfoot>

                  本文介绍了matplotlib 数据的 cx_freeze 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在 Debian 8 机器上使用 cx_freeze 冻结 Python 程序,但遇到以下错误消息:

                  I'm trying to freeze a Python program with cx_freeze, on a Debian 8 machine, but I run into this error message:

                  copying /usr/lib/python2.7/dist-packages/matplotlib/mpl-data -> build/exe.linux-x86_64-2.7/mpl-data
                  error: [Errno 2] No such file or directory: '/usr/lib/python2.7/dist-packages/matplotlib/mpl-data'
                  

                  我的 setup.py 文件包含:

                  from cx_Freeze import setup, Executable
                  
                  buildOptions = {
                      "excludes": ["PyQt5"]}
                  # PyQt5 conflicts with PyQt4
                  
                  base = None
                  
                  executables = [
                      Executable('test_fitfuns.py', base=base)
                  ]
                  
                  setup(name='testfitfuns',
                        version = '1.0',
                        description = 'test fit functions',
                        options = dict(build_exe = buildOptions),
                        executables = executables)
                  

                  我发现我的 mpl-data 目录在 "/usr/share/matplotlib/mpl-data" 中,所以我尝试将此行添加到 >buildOptions:

                  I figured out that my mpl-data directory is in "/usr/share/matplotlib/mpl-data", so I tried adding this line to buildOptions:

                  "include_files": [("/usr/share/matplotlib/mpl-data", "mpl-data")],
                  

                  如果我这样做,我的错误会变成:

                  If I do this, my error becomes:

                  error: [Errno 21] Is a directory: 'build/exe.linux-x86_64-2.7/mpl-data'
                  

                  接下来我应该尝试什么?

                  What should I try next?

                  这是我第一次尝试使用 cx_freeze,所以如果这是一个微不足道的问题,我深表歉意.

                  This is my first attempt at using cx_freeze, so I apologize if this is a trivial question.

                  推荐答案

                  问题是cx_freeze认为mpl-data目录在哪里引起的.具体来说,cx_Freeze.hooks 模块中的函数 load_matplotlib() 在 Linux 上创建了错误的路径(但在 Windows 上没有).

                  The problem is caused by where cx_freeze thinks the mpl-data directory lives. Specifically, the function load_matplotlib(), in the cx_Freeze.hooks module, creates the wrong path on Linux (but not on Windows).

                  def load_matplotlib(finder, module):
                      """the matplotlib module requires data to be found in mpl-data in the
                         same directory as the frozen executable so oblige it"""
                      dir = os.path.join(module.path[0], "mpl-data")
                      finder.IncludeFiles(dir, "mpl-data")
                  

                  在包装过程中会自动调用此函数来设置 mpl-data 目录的路径.它确实应该使用 matplotlib 包提供的 get_data_path() 函数,因为它返回所需的路径.

                  This function gets called automatically during the wrapping process to set the path to the mpl-data directory. It should really be using the get_data_path() function provided by the matplotlib package as this returns the required path.

                  了解所有这些后,我将以下内容添加到我的 setup.py 文件中.

                  Knowing all of this I added the following to my setup.py file.

                  import cx_Freeze.hooks
                  def hack(finder, module):
                      return
                  cx_Freeze.hooks.load_matplotlib = hack
                  

                  我在之后添加了这个

                  from cx_Freeze import setup, Executable
                  

                  然后我添加了

                   (matplotlib.get_data_path(), "mpl-data")
                  

                  到 build_options_dict 的 include_files 列表

                  To the include_files list for the build_options_dict

                  include_files =[              
                                  (matplotlib.get_data_path(), "mpl-data")
                                  #you may nay need to include other files 
                                  ]
                  build_options_dict ={"path" : apath, 
                                       "packages":packages,
                                       "include_files" :include_files,
                                       "excludes": excludes,
                                       "optimize":2
                                       }
                  

                  然后将 build_options_dict 提供给选项字典中的 cx_freeze 设置函数.

                  The build_options_dict is then supplied to the cx_freeze setup function in the options dictionary.

                  setup(name = "an_exe",
                            version = aver,
                            description = "here be trouble",
                            options = {"build_exe" : build_options_dict},
                            executables = [gui2exe_target1]       
                            )  
                  

                  现在有些人可能会说,写出来会更优雅

                  Now some may say that it would have been more elegant to have just written

                  def hack(finder, module):
                          finder.IncludeFiles(matplotlib.get_data_path(), "mpl-data")
                  

                  不要为包含文件列表中的额外内容而烦恼,我会说他们是对的.但是,我知道我写的东西有效,还没有测试更优雅的方法.

                  and not to have bothered with the extra stuff in the includes_files list and I would say they are right. However, I know what I wrote works and have yet to test the more elegant method.

                  这篇关于matplotlib 数据的 cx_freeze 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                  Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                  Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                  Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                  Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                  Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)
                      <legend id='EFQlo'><style id='EFQlo'><dir id='EFQlo'><q id='EFQlo'></q></dir></style></legend>
                        <tbody id='EFQlo'></tbody>

                        1. <i id='EFQlo'><tr id='EFQlo'><dt id='EFQlo'><q id='EFQlo'><span id='EFQlo'><b id='EFQlo'><form id='EFQlo'><ins id='EFQlo'></ins><ul id='EFQlo'></ul><sub id='EFQlo'></sub></form><legend id='EFQlo'></legend><bdo id='EFQlo'><pre id='EFQlo'><center id='EFQlo'></center></pre></bdo></b><th id='EFQlo'></th></span></q></dt></tr></i><div id='EFQlo'><tfoot id='EFQlo'></tfoot><dl id='EFQlo'><fieldset id='EFQlo'></fieldset></dl></div>

                          • <bdo id='EFQlo'></bdo><ul id='EFQlo'></ul>
                            <tfoot id='EFQlo'></tfoot>

                            <small id='EFQlo'></small><noframes id='EFQlo'>