繁体   English   中英

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

[英]ModuleNotFoundError: No module named 'keras_preprocessing' tensorflow2.2 with pip

我正在尝试使用以下命令从源代码构建tensorflow 2.2bazel 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不是您安装keras-preprocessing的 python 环境。

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

然后,使用以下 python 环境的路径重新启动bazel buildPYTHON_BIN_PATH=<result of the which python command>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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