我最近用Python3.6编写了一个库,并在Windows10上使用tkinter为它构建了一个GUI。
安装脚本运行得非常好(或者至少我找不到任何错误消息或警告),并且我可以从其中获取可执行文件。问题是,当我运行它时,我会得到以下错误消息:
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 *
,而tensorflow.python.profiler
中的profiler.py
尝试执行导致错误的导入。
我找到了导致错误的文件,当我在空闲的from tensorflow.core.profiler.tfprof_log_pb2 import OpLogProto
上运行时,它运行得非常好。
在达到这一点之前,我遇到了几个类似的问题( cx_Freeze构建没有显示任何警告或错误,但是.exe有一些import
错误),但是到目前为止,我可以自己修复它们,主要是通过将它们添加到安装脚本中的include_files
列表中。我试图对这个TensorFlow文件执行同样的操作,但是它没有工作。我还尝试将TensorFlow作为一个包包含在安装脚本中,或者在我的main.py
中直接导入它,但没有成功。
我的setup.py
如下所示(由于我尝试了很多事情,它可能包含了一些不必要的内容):
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及其依赖关系,但它也没有解决任何问题。
提前感谢!
发布于 2018-03-03 17:11:36
我能够通过在__init__.py
中创建一个空白的\path\to\python\Lib\site-packages\tensorflow\core\profiler
文件来解决这个问题。我正在运行python3.5.2和TensorFlow 1.5.0,因此这个解决方案可能特定于我的安装。
https://stackoverflow.com/questions/48123840
复制相似问题