ModuleNotFoundError:没有名为 'keras_preprocessing' tensorflow2.2 的模块,带有 pip



我正在尝试构建tensorflow 2.2从源代码使用命令:bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-msse4.2 --action_env PYTHON_BIN_PATH=/usr/bin/python3.8 //tensorflow/tools/pip_package:build_pip_package

如果我构建包,我得到错误:

ModuleNotFoundError: No module named 'keras_preprocessing'
然而,我有Keras-Preprocessing 1.1.0*已安装,应该是正确的版本。

我知道这个问题类似:ModuleNotFoundError: No module named 'keras_preprocessing'但我用的是pip而不是conda。如何用pip解决这个问题?

这是堆栈跟踪:

/home/brent/.cache/bazel/_bazel_brent/f717514c870df2340554ff84ed4b3c4d/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/python/keras/api/create_tensorflow.python_api_keras_python_api_gen_compat_v1.runfiles/org_tensorflow/tensorflow/python/ops/random_ops.py:285: SyntaxWarning: "is" with a literal. Did you mean "=="?
minval_is_zero = minval is 0  # pylint: disable=literal-comparison
/home/brent/.cache/bazel/_bazel_brent/f717514c870df2340554ff84ed4b3c4d/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/python/keras/api/create_tensorflow.python_api_keras_python_api_gen_compat_v1.runfiles/org_tensorflow/tensorflow/python/ops/random_ops.py:286: SyntaxWarning: "is" with a literal. Did you mean "=="?
maxval_is_one = maxval is 1  # pylint: disable=literal-comparison
/home/brent/.cache/bazel/_bazel_brent/f717514c870df2340554ff84ed4b3c4d/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/python/keras/api/create_tensorflow.python_api_keras_python_api_gen_compat_v1.runfiles/org_tensorflow/tensorflow/python/ops/ragged/ragged_batch_gather_with_default_op.py:84: SyntaxWarning: "is not" with a literal. Did you mean "!="?
if (default_value.shape.ndims is not 0
/home/brent/.cache/bazel/_bazel_brent/f717514c870df2340554ff84ed4b3c4d/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/python/keras/api/create_tensorflow.python_api_keras_python_api_gen_compat_v1.runfiles/org_tensorflow/tensorflow/python/ops/ragged/ragged_batch_gather_with_default_op.py:85: SyntaxWarning: "is not" with a literal. Did you mean "!="?
and default_value.shape.ndims is not 1):
Traceback (most recent call last):
File "/home/brent/.cache/bazel/_bazel_brent/f717514c870df2340554ff84ed4b3c4d/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/python/keras/api/create_tensorflow.python_api_keras_python_api_gen_compat_v1.runfiles/org_tensorflow/tensorflow/python/tools/api/generator/create_python_api.py", line 776, in <module>
main()
File "/home/brent/.cache/bazel/_bazel_brent/f717514c870df2340554ff84ed4b3c4d/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/python/keras/api/create_tensorflow.python_api_keras_python_api_gen_compat_v1.runfiles/org_tensorflow/tensorflow/python/tools/api/generator/create_python_api.py", line 755, in main
importlib.import_module(package)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/brent/.cache/bazel/_bazel_brent/f717514c870df2340554ff84ed4b3c4d/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/python/keras/api/create_tensorflow.python_api_keras_python_api_gen_compat_v1.runfiles/org_tensorflow/tensorflow/python/keras/datasets/imdb.py", line 25, in <module>
from tensorflow.python.keras.preprocessing.sequence import _remove_long_seq
File "/home/brent/.cache/bazel/_bazel_brent/f717514c870df2340554ff84ed4b3c4d/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/python/keras/api/create_tensorflow.python_api_keras_python_api_gen_compat_v1.runfiles/org_tensorflow/tensorflow/python/keras/preprocessing/__init__.py", line 23, in <module>
import keras_preprocessing
ModuleNotFoundError: No module named 'keras_preprocessing'
Target //tensorflow/tools/pip_package:build_pip_package failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: /home/brent/Documents/Projects/BenchmarkRCStrategiesSOTA/tensorflow/tensorflow/python/tools/BUILD:82:1 Executing genrule //tensorflow/python/keras/api:keras_python_api_gen failed (Exit 1)
INFO: Elapsed time: 14402.619s, Critical Path: 406.14s
INFO: 14101 processes: 14101 local.
FAILED: Build did NOT complete successfully

好的,我的猜测是/usr/bin/python3.8不是您安装的python环境-预处理.

您应该使用pip install重新安装它,然后使用以下命令打印python环境的路径:which python

然后,用python环境的路径重新启动bazel build:PYTHON_BIN_PATH=<result of the which python command>

相关内容

  • 没有找到相关文章

最新更新