【发布时间】:2018-05-31 16:32:15
【问题描述】:
在 python 3.5 32bit 中使用 3.3.1 pyinstaller,我将一个 .py 应用程序转换为 .exe
应用程序使用 tensorflow 并在某些时候抛出
Traceback (most recent call last):
File "face_classify.py", line 140, in <module>
loaded_model = load_c3d.c3d_model_obj(user_case)
File "load_c3d.py", line 80, in __init__
'wc1': _variable_with_weight_decay('wc1', [3, 3, 3, 3, 64], 0.0005),
File "load_c3d.py", line 47, in _variable_with_weight_decay
var = _variable_on_cpu(name, shape, tf.contrib.layers.xavier_initializer())
File "site-packages\tensorflow\__init__.py", line 35, in __getattr__
File "importlib\__init__.py", line 126, in import_module
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'tensorflow.contrib'
运行 .exe 时会发生这种情况。看起来像文件路径问题。 tensorflow 的__init__.py 就是这样做的
# Lazily import the `tf.contrib` module. This avoids loading all of the
# dependencies of `tf.contrib` at `import tensorflow` time.
def __getattr__(self, item):
global contrib
# Replace the lazy loader with the imported module itself.
import importlib # pylint: disable=g-import-not-at-top
contrib = importlib.import_module('tensorflow.contrib')
return getattr(contrib, item)
在我看来,这种延迟加载似乎无法被 pyinstaller 跟踪。但是 contrib 文件夹正确放置在我的 python 安装中:C:\Python35\Lib\site-packages\tensorflow\contrib我该如何解决这个问题?
【问题讨论】:
标签: python tensorflow pyinstaller