tensorflow: Python Configuration Error: 'PYTHON_BIN_PATH' environment variable is not set

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow): N/A
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Mac OS X Sierra
  • TensorFlow installed from (source or binary): N/A (compiling from HEAD)
  • TensorFlow version (use command below): N/A (see above)
  • Bazel version (if compiling from source): 0.4.5-homebrew
  • CUDA/cuDNN version: none (AMD GPU)
  • GPU model and memory: Radeon Pro 460
  • Exact command to reproduce:

sudo bazel build --config opt --copt=-msse4.1 --copt=-msse4.1 --copt=-mavx --copt=-mavx2 --copt=-mfma //tensorflow/tools/pip_package:build_pip_package

Describe the problem

Trying to build tensorflow from source (version installed via pip does not use some optimised CPU instructions), get the following error:

 ~/workspace/tensorflow   master  sudo bazel build --config opt --copt=-msse4.1 --copt=-msse4.1 --copt=-mavx --copt=-mavx2 --copt=-mfma //tensorflow/tools/pip_package:build_pip_package
WARNING: Config values are not defined in any .rc file: opt
ERROR: /Users/kachkach/workspace/tensorflow/third_party/py/numpy/BUILD:11:1: no such package '@local_config_python//': Traceback (most recent call last):
	File "/Users/kachkach/workspace/tensorflow/third_party/py/python_configure.bzl", line 180
		_create_python_repository(repository_ctx)
	File "/Users/kachkach/workspace/tensorflow/third_party/py/python_configure.bzl", line 157, in _create_python_repository
		_get_env_var(repository_ctx, _PYTHON_BIN_PATH)
	File "/Users/kachkach/workspace/tensorflow/third_party/py/python_configure.bzl", line 48, in _get_env_var
		_python_configure_fail("'%s' environment variable is no...)
	File "/Users/kachkach/workspace/tensorflow/third_party/py/python_configure.bzl", line 36, in _python_configure_fail
		fail("
%sPython Configuration Error:%...))

Python Configuration Error: 'PYTHON_BIN_PATH' environment variable is not set
 and referenced by '//third_party/py/numpy:headers'.
ERROR: Analysis of target '//tensorflow/tools/pip_package:build_pip_package' failed; build aborted.

Note that I used which python3 to find where my Python binary is located, and exported that as PYTHON_BIN_PATH, but it does not seem to help.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 25 (8 by maintainers)

Commits related to this issue

Most upvoted comments

<del>I think I finally found out the problem that caused my issue. So the problem is Anaconda</del>. Thanks to @MtDersvan and @Shoshin23 , It seems that the problem doesn’t only apply to Anaconda. But no matter what caused it, the problem seems to be that the building system did not set the path variable PYTHON_BIN_PATH correctly via the “.configure” file even though it seems to detect your path without any problem.

In order to solve it, you could simply try to export the variable it needed before the build with: export PYTHON_BIN_PATH = /home/ubuntu/anaconda3/bin/python or wherever your python binary is placed. Hopefully, it can help some of you guys.

Adding to @shadowfury330’s point, if you have TF Serving source checked out at master already, you can switch to the latest release by running:

git checkout 0.5.1
git submodule update

You should then be able to run bazel successfully.

For anyone who’s still getting this error: add --action_env=PYTHON_BIN_PATH=/usr/bin/python to ~/.bazelrc as per https://bazel.build/designs/2016/06/21/environment.html If you’re building from your own Dockerfile, adding ENV PYTHON_BIN_PATH=/usr/bin/python will be adequate.

@girving I had the same error when I’m build tensorflow-serving.And I’ve configured the tensorflow alreay.

Just want to make people aware of that you don’t need to wait for this to be solved if you don’t necessarily need to work with the latest RC version. I have just tested it with Tensorflow serving, and it works with its latest release (tag 0.5.1). You can simply clone that tag by running. git clone -b 0.5.1 --recurse-submodules https://github.com/tensorflow/serving For anyone who are using Tensorflow itself, you could do similar things such as: git clone -b v1.1.0 https://github.com/tensorflow/tensorflow I haven’t tested it for Tensorflow, if it still doesn’t work, you could switch to any earlier release which is over here.

Since https://github.com/tensorflow/tensorflow/pull/14467 it is again required to have the env variable PYTHON_BIN_PATH explicitly set, run configure script to set it, or to set it via --action_env.

@girving : Turns out I forgot to run configure on this instance (it was freshly cloned from HEAD), that fixed it for me but I’m leaving this open as some people seem to be having this problem even after running configure.