【问题标题】:cx_Freeze "no module named google" Errorcx_Freeze“没有名为 google 的模块”错误
【发布时间】:2018-02-18 05:44:18
【问题描述】:

我正在尝试冻结的 Python 脚本中使用 TensorFlow。一切都很好,但是当我尝试运行它时,我收到了这个错误:

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 确实在我的 TensorFlow 包含在构建目录中。我使用 Python 3.5.2 64 位和 TensorFlow 1.5.0 在 Windows 上运行

【问题讨论】:

    标签: python tensorflow cx-freeze


    【解决方案1】:

    没有名为“google”的模块

    要从 google 导入 google 或任何内容,google 目录中必须有一个 __init__.py 文件。 在 google 目录中创建该文件,您可以从中导入。 我有同样的问题。

    【讨论】:

    • 这个__init__.py 文件到底应该放在哪里?我可能放错地方了
    • 在 /google/ 目录中。除非目录具有初始化文件,否则无法识别模块。这也非常常见:import google.protobuf
    • 没有 google 目录。它到底会在哪里?
    • @JackNorthrup 请您详细说明如何创建 __init__.py 以便加载 google 模块。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-04
    • 1970-01-01
    • 2017-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多