我一直在按照教程在macOS上安装和构建Tensorflow。当我尝试构建它时,我使用以下命令:
bazel build --config=cuda --config=opt --copt=-msse4.2 --copt=-mpopcnt --copt=-maes --copt=-mcx16 --verbose_failures --action_env PATH --action_env LD_LIBRARY_PATH --action_env DYLD_LIBRARY_PATH //tensorflow/tools/pip_package:build_pip_package
几乎立即失败:
ERROR: /Users/psmith/tensorflow/third_party/py/numpy/BUILD:11:1: no such package '@local_config_python//': Traceback (most recent call last):
File "/Users/psmith/tensorflow/third_party/py/python_configure.bzl", line 291
_create_local_python_repository(repository_ctx)
File "/Users/psmith/tensorflow/third_party/py/python_configure.bzl", line 255, in _create_local_python_repository
_get_numpy_include(repository_ctx, python_bin)
File "/Users/psmith/tensorflow/third_party/py/python_configure.bzl", line 239, in _get_numpy_include
_execute(repository_ctx, [python_bin, "-c",..."], <2 more arguments>)
File "/Users/psmith/tensorflow/third_party/py/python_configure.bzl", line 54, in _execute
_fail("\n".join([error_msg.strip() if ... ""]))
File "/Users/psmith/tensorflow/third_party/py/python_configure.bzl", line 27, in _fail
fail(("%sPython Configuration Error:%...)))
Python Configuration Error: Problem getting numpy include path.
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
Is numpy installed?
and referenced by '//third_party/py/numpy:headers'
ERROR: Analysis of target '//tensorflow/tools/pip_package:build_pip_package' failed; build aborted: Loading failed
INFO: Elapsed time: 0.287s
FAILED: Build did NOT complete successfully (2 packages loaded)
currently loading: tensorflow/core ... (2 packages)
我已经测试并确认实际安装了numpy。我还强制升级并重新安装。我可以运行Python3&gt;导入numpy没有错误。
答案 0 :(得分:4)
我可以通过在bazel命令中添加以下内容来解决此错误:
--action_env PYTHON_BIN_PATH=/usr/bin/python
答案 1 :(得分:0)
验证python和numpy版本的安装位置非常有用。我正在安装Python 3.7,所以which python3.7
告诉我python可执行文件在哪里,并且正在运行
import numpy as np
np.__file__
交互式python会话中的内容告诉我numpy在哪里。
请牢记这些,输入.configure
后,在过程中出现提示时,请输入python的路径和相应的site-packages目录。
例如
Please specify the location of python.
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7
Found possible Python library paths:
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages