使用Pyinstaller时找不到隐藏的导入Tensorflow包

我正在尝试将我的对象检测器 python 项目转换为可执行文件,但我总是收到这些警告并且我的可执行文件无法运行。

64422 WARNING: Hidden import "tensorflow._api.v2.compat.v1.estimator" not found!
64425 WARNING: Hidden import "tensorflow._api.v2.compat.v2.compat.v2.keras.metrics" not found!
64843 WARNING: Hidden import "tensorflow._api.v2.compat.v1.compat.v1.keras.applications.resnet50" not found!
64844 WARNING: Hidden import "tensorflow._api.v2.compat.v1.compat.v1.keras.applications.resnet" not found!
64845 WARNING: Hidden import "tensorflow._api.v2.compat.v2.compat.v2.keras.backend" not found!
64857 WARNING: Hidden import "tensorflow._api.v2.compat.v1.compat.v1.estimator.tpu" not found!
64859 WARNING: Hidden import "tensorflow._api.v2.compat.v2.compat.v1.keras.applications.mobilenet" not found!
64892 WARNING: Hidden import "tensorflow._api.v2.compat.v1.compat.v1.keras.applications.vgg19" not found!
64894 WARNING: Hidden import "tensorflow._api.v2.compat.v2.compat.v2.keras.preprocessing.text" not found!
64896 WARNING: Hidden import "tensorflow._api.v2.compat.v1.compat.v1.estimator.tpu.experimental" not found!
64899 WARNING: Hidden import "tensorflow._api.v2.compat.v1.compat.v1.keras.applications.resnet_v2" not found!
64956 WARNING: Hidden import "tensorflow._api.v2.compat.v2.compat.v1.keras.wrappers.scikit_learn" not found!
64957 WARNING: Hidden import "tensorflow._api.v2.compat.v2.compat.v2.keras.applications.resnet50" not found!
64958 WARNING: Hidden import "tensorflow._api.v2.compat.v1.compat.v1.keras.wrappers.scikit_learn" not found!
65073 WARNING: Hidden import "tensorflow._api.v2.compat.v1.compat.v2.keras.applications.imagenet_utils" not found!
65073 WARNING: Hidden import "tensorflow._api.v2.compat.v1.compat.v2.keras.datasets.cifar100" not found!
65238 WARNING: Hidden import "tensorflow._api.v2.compat.v1.compat.v1.keras.optimizers" not found!

我的项目结构是

- project folder
  - venv
  - main.py
  - detect.py

在里面detect.py我有以下进口

import tensorflow as tf
from tensorflow.python.saved_model import tag_constants
from tensorflow.compat.v1 import ConfigProto
from tensorflow.compat.v1 import InteractiveSession

tensorflow module可以在发现site-packages里面venv的文件夹

我尝试过的解决方案是添加--hidden-import tensorflow这个问题中所说的标志

pyinstaller --hidden-import tensorflow --onefile main.py

我也通过创建一个包含文件的目录来尝试 这种方法hookshook-tensorflow.py

- project folder
   - venv
   - hooks
      - hook-tensorflow.py
   - main.py
   - detect.py

钩张量流.py

from PyInstaller.utils.hooks import collect_all


def hook(hook_api):
    packages = [
        'tensorflow'
    ]
    for package in packages:
        datas, binaries, hiddenimports = collect_all(package)
        hook_api.add_datas(datas)
        hook_api.add_binaries(binaries)
        hook_api.add_imports(*hiddenimports)

然后发出这个终端命令

pyinstaller --additional-hooks-dir=hooks --onefile main.py

但是,同样的警告仍然存在,我的可执行文件无法运行。

以上是使用Pyinstaller时找不到隐藏的导入Tensorflow包的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>