Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python Configuration Error: 'PYTHON_BIN_PATH' environment variable is not set #9436

Closed
halflings opened this issue Apr 25, 2017 · 25 comments
Closed
Assignees
Labels
type:build/install Build and install issues

Comments

@halflings
Copy link

halflings commented Apr 25, 2017

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.

@halflings
Copy link
Author

Also (unrelated), the tools/tf_env_collect.sh script does not work::

bash tools/tf_env_collect.sh
Collecting system information...
cat: /proc/1/cgroup: No such file or directory
tools/tf_env_collect.sh: line 31: syntax error near unexpected token `>'
tools/tf_env_collect.sh: line 31: `c++ --version &>> $OUTPUT_FILE'

@girving
Copy link
Contributor

girving commented Apr 25, 2017

Did you run configure?

@girving girving added stat:awaiting response Status - Awaiting response from author type:build/install Build and install issues labels Apr 25, 2017
@haiy
Copy link

haiy commented Apr 26, 2017

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

@girving
Copy link
Contributor

girving commented Apr 26, 2017

@caisq Is tf_env_collect supposed to work on Mac? It appears Linux only since it has an unguarded reference to /proc.

@caisq
Copy link
Contributor

caisq commented Apr 26, 2017

cc @aselle (author) for whether tf_env_collect.sh is supposed to work on Mac.

@harshthaker
Copy link

I am getting the same error trying to run command 'bazel build --config opt tensorflow/examples/image_retraining:retrain' Error: 'PYTHON_BIN_PATH' environment variable is not set and referenced by '//util/python:python_headers'.

@hantingxie
Copy link

I think this is a recent problem with the current master's source codes. I tested the compilation of Tensorflow serving both locally and in docker. Both environments gave me the same error "Python Configuration Error: 'PYTHON_BIN_PATH' environment variable is not set". Of course, I set the configure before the build. In fact, I was able to successfully compile Tensorflow under the same environment with the same configuration a few weeks ago and there was no problem. So this must be a recent issue.

The full error message is:
`ERROR: /root/.cache/bazel/_bazel_root/f8d1071c69ea316497c31e40fe01608c/external/org_tensorflow/util/python/BUILD:5:1: no such package '@local_config_python//': Traceback (most recent call last):
File "/root/.cache/bazel/_bazel_root/f8d1071c69ea316497c31e40fe01608c/external/org_tensorflow/third_party/py/python_configure.bzl", line 180
_create_python_repository(repository_ctx)
File "/root/.cache/bazel/_bazel_root/f8d1071c69ea316497c31e40fe01608c/external/org_tensorflow/third_party/py/python_configure.bzl", line 157, in _create_python_repository
_get_env_var(repository_ctx, _PYTHON_BIN_PATH)
File "/root/.cache/bazel/_bazel_root/f8d1071c69ea316497c31e40fe01608c/external/org_tensorflow/third_party/py/python_configure.bzl", line 48, in _get_env_var
_python_configure_fail("'%s' environment variable is no...)
File "/root/.cache/bazel/_bazel_root/f8d1071c69ea316497c31e40fe01608c/external/org_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`

@girving
Copy link
Contributor

girving commented Apr 26, 2017

@jart Do you know what the issue might be?

@girving girving added stat:awaiting response Status - Awaiting response from author stat:awaiting tensorflower Status - Awaiting response from tensorflower and removed stat:awaiting response Status - Awaiting response from author labels Apr 26, 2017
@neocortical
Copy link

I just ran into this issue as well. I am compiling in an Ubuntu 14.04 Docker container (using the standard Dockerfile.devel image).

@hantingxie
Copy link

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.

@neocortical
Copy link

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.

@halflings
Copy link
Author

@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.

@girving girving closed this as completed Apr 27, 2017
@girving girving reopened this Apr 27, 2017
@hantingxie
Copy link

hantingxie commented May 8, 2017

I think I finally found out the problem that caused my issue. So the problem is Anaconda. 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.

@MtDersvan
Copy link
Contributor

@hantingxie I have the same problem, but I'm building tensorflow-serving using standard Dockerfile.devel image as @neocortical did. So it might not be specifically only Anaconda related problem. Also, it worked for me just couple weeks before with the same configuration.

@hantingxie
Copy link

@MtDersvan Good to hear that you solved it. I agree with you, this issue might be caused by several different reasons. Anaconda can be one of them.

@Shoshin23
Copy link

Hi, it seems to be working fine for me with @hantingxie 's solution. For some reason desipte ./configure recognizing my default path I still had to manually set my PYTHON_BIN_PATH. And yes, this is happening in the default dockerfile that's mentioned in the tensorflow serving docs.

@jart
Copy link
Contributor

jart commented May 24, 2017

There's a possibility this is a bug upstream in Bazel. Maybe --action_env is not being passed along to repository_ctx properly.

@jart
Copy link
Contributor

jart commented May 24, 2017

@nlopezgi should know about this issue.

@jart jart removed the stat:awaiting tensorflower Status - Awaiting response from tensorflower label May 24, 2017
@jart jart self-assigned this May 24, 2017
jart added a commit to jart/tensorflow that referenced this issue May 24, 2017
jart added a commit to jart/tensorflow that referenced this issue May 26, 2017
drpngx pushed a commit to drpngx/tensorflow that referenced this issue Jun 30, 2017
- Remove experimental attributes (local_checks, python_include, numpy_include, remote_config_repo). Use of experimental remote repo can only be enabled now via env variable (preferred to change to workspace file)
- Fix hardcoded fallback value for python bin. New fallback is to use 'which python' and fail if python not set in path (solves tensorflow#9436 / works around bazelbuild/bazel#3057).
- Fixes minor issues with template: adds spaces to srcs in genrule, remove extra space after genrules.
- Some dead code clean up (use of empty configuration)

PiperOrigin-RevId: 160594421
@charlesjohannisen
Copy link

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.

@RobRomijnders
Copy link

Might be unrelated for many, but this is how I circumvented the error. I am installing in a virtual env.

I installed the virtualenv library in python3.5. Upon making the env, I point to the binaries for python3.6. This gives me the error.

Now I solved the problem as follows. I install virtualenv for python3.6 and use that to make an env. In this env, this above error does not occur.

@sxp4u
Copy link

sxp4u commented Dec 5, 2017

I solve the same problem by adding the PYTHON_BIN_PATH to " ~/.bash_profile ".

If you don't have a Environment Parameter named PYTHON_BIN_PATH, the error msg will be ['PYTHON_BIN_PATH' environment variable is not set], if you already have one but not correct, the error msg would be [ PYTHON_BIN_PATH is not executable ].

Note that the PYTHON_BIN_PATH should specify to ".../bin/python" instead of ".../bin ", the latter would raise the [ not executable ] error.

@nlopezgi
Copy link
Contributor

nlopezgi commented Dec 5, 2017

Since #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.

@sxp4u
Copy link

sxp4u commented Dec 6, 2017 via email

@mirwisek
Copy link

I have the same issue, none of the above solution worked for me.

I'm getting the following error in Windows 10 x64:

C:/users/{user}/_bazel_{user}/sudrsvim/external/tf_toolchains/toolchains/remote_config/configs.bzl:6:28: in initialize_rbe_configs
  C:/users/{user}/_bazel_{user}/sudrsvim/external/tf_toolchains/toolchains/remote_config/rbe_config.bzl:158:27: in _tensorflow_local_config
Repository rule local_python_configure defined at:
  C:/users/{user}/_bazel_{user}/sudrsvim/external/org_tensorflow/third_party/py/python_configure.bzl:275:41: in <toplevel>
ERROR: An error occurred during the fetch of repository 'local_execution_config_python':
   Traceback (most recent call last):
        File "C:/users/{user}/_bazel_{user}/sudrsvim/external/org_tensorflow/third_party/py/python_configure.bzl", line 209, column 22, in _create_local_python_repository
                _check_python_bin(repository_ctx, python_bin)
        File "C:/users/{user}/_bazel_{user}/sudrsvim/external/org_tensorflow/third_party/py/python_configure.bzl", line 145, column 25, in _check_python_bin
                auto_config_fail("--define %s='%s' is not executable. Is it the python binary?" % (
        File "C:/users/{user}/_bazel_{user}/sudrsvim/external/org_tensorflow/third_party/remote_config/common.bzl", line 12, column 9, in auto_config_fail
                fail("%sConfiguration Error:%s %s\n" % (red, no_color, msg))
Error in fail: Configuration Error: --define PYTHON_BIN_PATH='C:\Users\{user}\AppData\Local\Microsoft\WindowsApps\python3.exe' is not executable. Is it the python binary?

I thought it must be an OS issue, I tried on Ubuntu 18.04 LTS (Windows Subsystem).

Then I got the same error with

ERROR: An error occurred during the fetch of repository 'local_execution_config_python':
   Traceback (most recent call last):
        File "/home/mirwisek/.cache/bazel/_bazel_mirwisek/da48a9b0cd92faf980f30b2a4925b53a/external/org_tensorflow/third_party/py/python_configure.bzl", line 212, column 41, in _create_local_python_repository
                python_include = _get_python_include(repository_ctx, python_bin)
        File "/home/mirwisek/.cache/bazel/_bazel_mirwisek/da48a9b0cd92faf980f30b2a4925b53a/external/org_tensorflow/third_party/py/python_configure.bzl", line 152, column 21, in _get_python_include
                result = execute(
        File "/home/mirwisek/.cache/bazel/_bazel_mirwisek/da48a9b0cd92faf980f30b2a4925b53a/external/org_tensorflow/third_party/remote_config/common.bzl", line 230, column 13, in execute
                fail(
Error in fail: Problem getting python include path.
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: cannot import name 'sysconfig'
Is the Python binary path set up right? (See ./configure or PYTHON_BIN_PATH.) Is distutils installed?

Yes, Python is installed correctly and I can use it with python3 on CMD as well as terminal. I tried to define the PYTHON_BIN_PATH in system variable to the location of python3, that didn't work.

@charlesjohannisen
Copy link

@mirwisek, or anyone else on this thread, which parts of tensorflow do you intend to use? There might be a docker container available for your use case. My original interest in tensorflow was syntaxnet, for which I found and subsequently forked a more user friendly version of the syntaxnet container. Point is, the containers are much more reliable than building and running the source.

lngart pushed a commit to lngart/GitSubSep that referenced this issue Oct 5, 2021
- Remove experimental attributes (local_checks, python_include, numpy_include, remote_config_repo). Use of experimental remote repo can only be enabled now via env variable (preferred to change to workspace file)
- Fix hardcoded fallback value for python bin. New fallback is to use 'which python' and fail if python not set in path (solves tensorflow/tensorflow#9436 / works around bazelbuild/bazel#3057).
- Fixes minor issues with template: adds spaces to srcs in genrule, remove extra space after genrules.
- Some dead code clean up (use of empty configuration)

PiperOrigin-RevId: 160594421
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:build/install Build and install issues
Projects
None yet
Development

No branches or pull requests