cx_Freeze没有找到一些TensorFlow导入

问题描述 投票:3回答:1

我最近写了一个库(在Python 3.6中),并在Windows 10上使用tkinter为它构建了一个GUI.GUI现在已经完成,我正在尝试使用cx_Freeze来冻结它。

安装脚本运行完全正常(或者至少我无法发现任何错误消息或警告),我可以从中获取可执行文件。问题是,当我运行它时,我收到以下错误消息:

File "C:\Program Files\Python36\lib\site-packages\tensorflow\python\profiler\profiler.py", line 22 in <module>
from tensorflow.core.profiler.tfprof_log_pb2 import OpLogProto
ModuleNotFoundError: No module named 'tensorflow.core.profiler.tfprof_log_pb2'

这里提到TensorFlow的原因是我的库使用TensorFlow,当然,我的GUI也是如此。整个错误消息说的是当我导入tensorflow(import tensorflow as tf)时,程序尝试在from tensorflow.python import *中执行profiler.pytensorflow.python.profiler然后尝试执行导致错误的导入。

我找到了导致错误的文件,当我在IDLE from tensorflow.core.profiler.tfprof_log_pb2 import OpLogProto上做的时候,它完全正常。

在达到这一点之前,我遇到了几个类似的问题(cx_Freeze构建没有显示任何警告或错误,但.exe有一些import错误),但我到目前为止可以自己修复它们,主要是通过将它们添加到列表中在安装脚本中的include_files。我尝试对此TensorFlow文件执行相同操作,但它不起作用。我也尝试在设置脚本中包含TensorFlow作为包,或者直接在我的main.py中导入它,但没有成功。

我的setup.pyis如下(可能有一些不必要的包括它,因为我尝试了很多东西):

from cx_Freeze import setup, Executable
import os
import sys

os.environ['TCL_LIBRARY'] = "C:\\Program Files\\Python36\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Program Files\\Python36\\tcl\\tk8.6"

base = None
if sys.platform == "win32":
    base = "Win32GUI"

includes = ["tkinter", "_tkinter", "numpy.core._methods", "numpy.lib.format", "tensorflow"]
include_files = ["C:\\Program Files\\Python36\\DLLs\\tcl86t.dll",
                 "C:\\Program Files\\Python36\\DLLs\\tk86t.dll",
                 "C:\\Program Files\\Python36\\DLLs\\_tkinter.pyd",
                 "C:\\Program Files\\Python36\\Lib\\site-packages\\tensorflow\\core\\profiler\\tfprof_log_pb2.py",
                 "C:\\Program Files\\Python36\\Lib\\site-packages\\tensorflow\\python\\profiler\\profiler.py",
                 "C:\\Program Files\\Python36\\Lib\\site-packages\\tensorflow\\include\\tensorflow\\core\\profiler\\tfprof_log.pb.h"]
packages = []

setup(name = "Ap'Pear",
      version = "0.1",
      description = "Test executable",
      options = {"build_exe": { "includes": includes, "include_files": include_files, "packages": packages}},
      executables = [Executable(script = "main.py", targetName = "Ap'Pear.exe", base = base, icon = "images/icon.ico")],
      )

我尝试从头开始重建TensorFlow及其依赖项,但它也没有解决任何问题。

提前致谢!

python tensorflow python-3.6 cx-freeze
1个回答
2
投票

我能够通过在__init__.py中创建一个空白的\path\to\python\Lib\site-packages\tensorflow\core\profiler文件来解决这个问题。我正在运行python 3.5.2和TensorFlow 1.5.0,所以这个解决方案可能特定于我的安装。

© www.soinside.com 2019 - 2024. All rights reserved.