简体   繁体   中英

Getting AttributeError: module 'tensorflow_estimator.python.estimator.api.estimator' has no attribute '__file__' when running a cx_Freeze executable

I'm trying to compile this python script:

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()

Using this script:

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

But I get the error in the title when I run the executable. I even tried to reinstall every tensorflow package with no result. I'm working on a virtual environment.

Full log:

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__'

Try to add to tensorflow and maybe tensorflow_estimator and keras to the --include-modules comma-separated list.

Or try to use the distutils setup script and to add tensorflow and maybe tensorflow_estimator and keras to the packages list of the build_exe option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM