栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用pyinstaller和mayavi import创建独立的exe

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用pyinstaller和mayavi import创建独立的exe

我处理了同样的问题,最后切换到cx_freeze,现在在Linux和Windows上都可以正常工作。您正在处理的问题源于您发现的SE答案之类的语句,即动态导入语句,其中导入的内容仅在运行时确定:

    be = 'pyface.ui.%s.' % tk    __import__(be + 'init')

当您在构建文件中明确添加所需的软件包时,我无法在pyinstaller中修复该问题,而在cx_freeze中它可以工作。这是我使用的软件包列表:

"packages": ["pyface.ui.qt4", "tvtk.vtk_module", "tvtk.pyface.ui.wx", "matplotlib.backends.backend_qt4",'pkg_resources._vendor','pkg_resources.extern','pygments.lexers',        'tvtk.pyface.ui.qt4','pyface.qt','pyface.qt.QtGui','pyface.qt.QtCore','numpy','matplotlib','mayavi']

这是一个完整的构建脚本,可与python3.6,cx_freeze 5.0.2,mayavi 4.5.0 + vtk71,特征4.6.0,pyface
5.1.0和traitsui 5.1.0一起使用。

import osfrom cx_Freeze import setup, Executableimport cx_Freeze.hooksdef hack(finder, module):    returncx_Freeze.hooks.load_matplotlib = hackimport scipyimport matplotlibscipy_path = os.path.dirname(scipy.__file__) #use this if you are also using scipy in your applicationbuild_exe_options = {"packages": ["pyface.ui.qt4", "tvtk.vtk_module", "tvtk.pyface.ui.wx", "matplotlib.backends.backend_qt4",'pygments.lexers', 'tvtk.pyface.ui.qt4','pyface.qt','pyface.qt.QtGui','pyface.qt.QtCore','numpy','matplotlib','mayavi'],          "include_files": [(str(scipy_path), "scipy"), #for scipy         (matplotlib.get_data_path(), "mpl-data"),],          "includes":['PyQt4.QtCore','PyQt4.QtGui','mayavi','PyQt4'],          'excludes':'Tkinter',         "namespace_packages": ['mayavi']         }executables = [    Executable('main.py', targetName="main.exe",base = 'Win32GUI',)]setup(name='main',      version='1.0',      description='',      options = {"build_exe": build_exe_options},      executables=executables,      )

我通过以下方式导入pyface:

os.environ['ETS_TOOLKIT'] = 'qt4'import imptry:    imp.find_module('PySide') # test if PySide if availableexcept importError:    os.environ['QT_API'] = 'pyqt' # signal to pyface that PyQt4 should be usedfrom pyface.qt import QtGui, QtCore

导入mayavi之前



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/659620.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号