简体   繁体   English

Py2app 应用程序不适用于 tensorflow

[英]Py2app application not working with tensorflow

I have made a GUI application that uses Tensorflow to load in a model from a .h5 file and get a prediction.我制作了一个 GUI 应用程序,它使用 Tensorflow 从 .h5 文件加载模型并获得预测。 The program works fine when running it from a terminal before putting it together into an application.该程序在将其组合到应用程序中之前从终端运行时运行良好。 However, when I use py2app to make the application, I get an error from tensorflow_core.但是,当我使用 py2app 制作应用程序时,我收到来自 tensorflow_core 的错误。

I have tried using Python3 to put the application together and get a number of other errors when doing so.我曾尝试使用 Python3 将应用程序放在一起,并在这样做时遇到了许多其他错误。

Here are my imports regarding Tensorflow (in the Bay.py file):这是我关于 Tensorflow 的导入(在 Bay.py 文件中):

from tensorflow.keras import models
import tkFileDialog as filedialog
import tensorflow as tf

When I run python setup.py py2app everything runs fine and the application is created, but when I try to open the application I get this error in the terminal:当我运行python setup.py py2app一切都运行良好并且应用程序已创建,但是当我尝试打开应用程序时,我在终端中收到此错误:

from tensorflow_core import *
File "tensorflow_core/__init__.pyc", line 40, in <module>
ImportError: No module named tools

I have been Googling and searching for how to fix this problem for days.几天来,我一直在谷歌搜索并寻找如何解决这个问题。 I tried using tensorflow, keras, and even tensorflow.keras.models as packages in the setup.py file but that don't work either.我尝试在 setup.py 文件中使用 tensorflow、keras 甚至 tensorflow.keras.models 作为包,但这也不起作用。 Here is my setup.py file:这是我的 setup.py 文件:

from setuptools import setup

APP = ['Bay.py']
DATA_FILES = [
 'Bay0.jpg',
 'Bay1.jpg',
 'Bay2.jpg',
 'Bay3.jpg',
 'Bay4.jpg',
 'Bia0.jpg',
 'Bia1.jpg',
 'Bia2.jpg',
 'Bia3.jpg',
 'Bia4.jpg',
 'Sun0.jpg',
 'Sun1.jpg',
 'Sun2.jpg',
 'Sun3.jpg',
 'Sun4.jpg',
 'CoverPage1.jpg',
 'Model/model.h5',
 'Collage/img1.jpg',
 'Collage/img2.jpg',
 'Collage/img3.jpg',
 'Collage/img4.jpg',
 'Collage/img5.jpg',
 'Collage/img6.jpg',
 'Collage/img7.jpg',
 'Collage/img8.jpg',
 'Collage/img9.jpg',
 'Collage/img10.jpg',
 'Collage/img11.jpg',
 'Collage/img12.jpg',
 'Collage/img13.jpg',
 'Collage/img14.jpg',
 'Collage/img15.jpg',
 'Collage/img16.jpg',
 'Collage/img17.jpg',
 'Collage/img18.jpg',
 'Collage/img19.jpg',
 'Collage/img20.jpg',
 'Collage/img21.jpg',
 'Collage/img22.jpg',
 'Collage/img23.jpg',
 'Collage/img24.jpg']
OPTIONS = {'argv_emulation': True,
    'iconfile':'Bay3.icns',
    'packages':['tensorflow','keras']}

setup(
    app=APP,
    name = "App",
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

Adding "tensorflow_core" to the "packages" option might work.将“tensorflow_core”添加到“packages”选项可能会起作用。

Is this something that is reproducible with a trivial script using tensorflow?这是否可以通过使用 tensorflow 的简单脚本重现? If so, could you file a bug at the py2app tracker?如果是这样,您能否在 py2app 跟踪器上提交错误?

And finally, why do you use the argv_emulation option?最后,为什么要使用 argv_emulation 选项? In general it is better to avoid using the argv emulator with GUI scripts, but use the GUI toolkit's method for reacting to file-open events.一般来说,最好避免将 argv 模拟器与 GUI 脚本一起使用,而是使用 GUI 工具包的方法来响应文件打开事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM