I'm trying to build an app on Ubuntu 20.04, where python3 points to Python3.8, and I'm building aganist Python3.6
I have the following runtime in the same directory of WORKSPACE.
$ cat BUILD.bazel
py_runtime(
name = "python3.6",
interpreter_path = "/usr/bin/python3.6",
)
I tried to build the app by running the following and bazel still points to python3 which is python3.8
bazelisk build company/app_api:app --python_top=//:python3.6
I also tried the deprecated option and didn't work either.
bazelisk build company/app_api:app --python_path=/usr/bin/python3.6
This is the error I get:
...
subprocess.CalledProcessError: Command '['/usr/bin/python3', '-m', 'pip', '--isolated', 'wheel', '-r', '/source_code/src/python/third_party/requirements.txt']' returned non-zero exit status 1.
...
pip is trying to install a package that works only with python3.6, and that's why it's returning a non zero exist code.
How do I force bazel to use a custom python interpreter?
py_runtime
usually must be used withpy_runtime_pair
andtoolchain
. See the example in thepy_runtime_pair
documentation. That example, slightly modified to apply to the OP would look like:Then one can use the new toolchain by placing
register_toolchains("//path/to/python3:py3-tc")
in theWORKSPACE
file or passing the--extra_toolchains //path/to/python3:py3-tc
command line flag.Add python_interpreter to pip_install in WORKSPACE.