获取AttributeError:运行cx_Freeze可执行文件时,模块'tensorflow_estimator.python.estimator.api.estimator'没有属性'__file__'

时间:2019-03-09 12:00:59

标签: python tensorflow executable cx-freeze

我正在尝试编译此python脚本:

from keras import optimizers
from keras.models import Sequential
from keras.models import model_from_json


from keras.layers import Dense, Flatten

import time
import tkinter
import cv2
import PIL.Image, PIL.ImageTk
from matplotlib import pyplot as plt
import numpy as np
import pickle
from pathlib import Path

import threading

input("waiting for input")
exit()

使用此脚本:

cxfreeze test.py --target-dir dist --include-modules=numpy.core._methods,numpy.lib.format,tensorflow.python.tf2,tensorflow.python.tools.component_api_helper

但是运行可执行文件时,标题出现错误。我什至尝试重新安装每个tensorflow软件包,但没有结果。我正在虚拟环境中工作。

完整日志:

davidaffo@davidaffo-TM1701:~/PycharmProjects/EyeTracker$ source ./venv/bin/activate
(venv) davidaffo@davidaffo-TM1701:~/PycharmProjects/EyeTracker$ ./dist/test
Using TensorFlow backend.
Traceback (most recent call last):
  File "/home/davidaffo/PycharmProjects/EyeTracker/venv/lib/python3.6/site-packages/cx_Freeze/initscripts/__startup__.py", line 14, in run
    module.run()
  File "/home/davidaffo/PycharmProjects/EyeTracker/venv/lib/python3.6/site-packages/cx_Freeze/initscripts/Console.py", line 26, in run
    exec(code, m.__dict__)
  File "test.py", line 1, in <module>
    from keras import optimizers
  File "/home/davidaffo/PycharmProjects/EyeTracker/venv/lib/python3.6/site-packages/keras/__init__.py", line 3, in <module>
    from . import utils
  File "/home/davidaffo/PycharmProjects/EyeTracker/venv/lib/python3.6/site-packages/keras/utils/__init__.py", line 6, in <module>
    from . import conv_utils
  File "/home/davidaffo/PycharmProjects/EyeTracker/venv/lib/python3.6/site-packages/keras/utils/conv_utils.py", line 9, in <module>
    from .. import backend as K
  File "/home/davidaffo/PycharmProjects/EyeTracker/venv/lib/python3.6/site-packages/keras/backend/__init__.py", line 89, in <module>
    from .tensorflow_backend import *
  File "/home/davidaffo/PycharmProjects/EyeTracker/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 5, in <module>
    import tensorflow as tf
  File "/home/davidaffo/PycharmProjects/EyeTracker/venv/lib/python3.6/site-packages/tensorflow/__init__.py", line 29, in <module>
    from tensorflow._api.v1 import compat
  File "/home/davidaffo/PycharmProjects/EyeTracker/venv/lib/python3.6/site-packages/tensorflow/_api/v1/compat/__init__.py", line 21, in <module>
    from tensorflow._api.v1.compat import v1
  File "/home/davidaffo/PycharmProjects/EyeTracker/venv/lib/python3.6/site-packages/tensorflow/_api/v1/compat/v1/__init__.py", line 626, in <module>
    child_package_str=('tensorflow_estimator.python.estimator.api.estimator'))
  File "/home/davidaffo/PycharmProjects/EyeTracker/venv/lib/python3.6/site-packages/tensorflow/python/tools/component_api_helper.py", line 85, in package_hook
    set_child_as_subpackage()
  File "/home/davidaffo/PycharmProjects/EyeTracker/venv/lib/python3.6/site-packages/tensorflow/python/tools/component_api_helper.py", line 69, in set_child_as_subpackage
    os.path.join(os.path.dirname(child_pkg.__file__), ".."))]
AttributeError: module 'tensorflow_estimator.python.estimator.api.estimator' has no attribute '__file__'

1 个答案:

答案 0 :(得分:0)

尝试添加到tensorflow以及tensorflow_estimatorkeras--include-modules的逗号分隔列表中。

或者尝试使用distutils setup script并将tensorflow以及tensorflow_estimatorkeras添加到packages选项的build_exe列表中