cx_Freeze“no module named google”错误

5

我正在使用TensorFlow在Python脚本中进行开发,现在我想要对其进行冻结。所有的构建都很顺利,但是当我尝试运行时却遇到了以下错误:

Traceback (most recent call last):
  File "C:\Users\mthun\AppData\Local\Programs\Python\Python35\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
    module.run()
  File "C:\Users\mthun\AppData\Local\Programs\Python\Python35\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
    exec(code, m.__dict__)
  File "app.py", line 2, in <module>
  File "D:\code\Github\codes-at-home\retrain.py", line 16, in <module>
    import tensorflow as tf
  File "C:\Users\mthun\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "C:\Users\mthun\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\__init__.py", line 52, in <module>
    from tensorflow.core.framework.graph_pb2 import *
  File "C:\Users\mthun\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\core\framework\graph_pb2.py", line 6, in <module>
    from google.protobuf import descriptor as _descriptor
ImportError: No module named 'google'

我有两个本地的Python文件作为模块导入到我的主要脚本中,它们都导入了TensorFlow。未冻结时应用程序完全正常工作。

这是我的setup.py

import sys
import os
from cx_Freeze import setup, Executable

PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {
    "packages": ["os"],
    'include_files': [
        'MISTER-BRAINWASH.ico',
        os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tk86t.dll'),
        os.path.join(PYTHON_INSTALL_DIR, 'DLLs', 'tcl86t.dll')
    ],
    "includes":['retrain','label_image','numpy.core._methods', 'numpy.lib.format']
}

# GUI applications require a different base on Windows (the default is for a console application).
base = None

executables = [
    Executable("app.py", base=base, icon='MISTER-BRAINWASH.ico'),
]

setup(
    name="Taxon",
    version="0.1",
    description="retrain inception with a GUI",
    options={"build_exe": build_exe_options},
    executables=executables
)

我查看了我的构建目录,google确实在其中包含。我正在使用Python 3.5.2 64位和TensorFlow 1.5.0在Windows上运行。

1个回答

8

没有名为 'google' 的模块

要导入 google 或来自 google 的任何内容,必须在 google 目录中有一个 __init__.py 文件。 创建该文件并放置于 google 目录中,即可从中导入。 我曾遇到同样的问题。


这个 __init__.py 文件应该放在哪里?我可能把它放错了地方。 - Mike Delmonaco
在 /google/ 目录中,除非该目录有一个 init 文件,否则模块将不被识别。这也是使用 import google.protobuf 时非常常见的情况。 - JackNorthrup
2
没有谷歌目录。它会在哪里呢? - Anesh
@JackNorthrup 你能否详细说明如何创建 __init__.py 文件以便加载 google 模块。 - Jimit Vaghela

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接