rules_python icon indicating copy to clipboard operation
rules_python copied to clipboard

[env python] failed on MacOS 12.3, as python2 removed

Open honwen opened this issue 3 years ago • 4 comments

🐞 bug report

Affected Rule

The issue is caused by the rule:

Is this a regression?

Yes, the previous version in which this bug was not present was: ....

MacOS 12.2.1

Description

A clear and concise description of the problem...

🔬 Minimal Reproduction

OS: MacOS 12.3 Bazel: 5.0.0

bazel5 run //examples:py_import_example

🔥 Exception or Error




INFO: Analyzed 2 targets (24 packages loaded, 318 targets configured).
INFO: Found 1 target and 1 test target...
[0 / 5] [Prepa] BazelWorkspaceStatusAction stable-status.txt ... (4 actions, 0 running)
FAIL: //:py_import_test (see /private/var/tmp/***/execroot/py_import/bazel-out/darwin-fastbuild/testlogs/py_import_test/test.log)
INFO: From Testing //:py_import_test:
==================== Test output for //:py_import_test:
env: python: No such file or directory
================================================================================
INFO: Elapsed time: 93.025s, Critical Path: 2.22s
INFO: 6 processes: 4 internal, 2 darwin-sandbox.
INFO: Build completed, 1 test FAILED, 6 total actions
//:py_import_test                                                        FAILED in 0.8s
  /private/var/tmp/***/execroot/py_import/bazel-out/darwin-fastbuild/testlogs/py_import_test/test.log

Executed 1 out of 1 test: 1 fails locally.
INFO: Build completed, 1 test FAILED, 6 total actions
copying workspace under test examples/py_import to /private/var/tmp/***/execroot/rules_python/_tmp/12d36418595ed21d10a139c999170d5f/tmp4adyy1pw/wksp

testlogs/py_import_test/test.log:

exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //:py_import_test
-----------------------------------------------------------------------------
env: python: No such file or directory

🌍 Your Environment

Operating System:

  
MacOS 12.3
M1 pro
  

Output of bazel version:

  
5.0.0
  

Rules_python version:

  
commit/e18e1a3bbd372fd0351277794155b5b9045fbe37
  

Anything else relevant?

honwen avatar Mar 17 '22 07:03 honwen

Thanks for your issue report. Unfortunately, by default rules_python will lookup python on the system in its stub script.

The workarounds are:

  • install python onto the system or alias an existing python3.
  • Replace python in the stub script, similar to https://github.com/bazelbuild/rules_python/pull/699.

thundergolfer avatar Jun 14 '22 13:06 thundergolfer

Thanks for your issue report. Unfortunately, by default rules_python will lookup python on the system in its stub script.

The workarounds are:

Unfortunately, rules_apple does not seem to export the PATH set by the user (cf. run.use_default_shell_env)

so this can not work

install python onto the system or alias an existing python3.

honwen avatar Jul 12 '22 09:07 honwen

Same root cause as: https://github.com/bazelbuild/rules_python/issues/691

groodt avatar Jul 13 '22 04:07 groodt

A solution showcase

py_runtime(
    name = "python3_runtime",
    files = ["@python_interpreter//:files"],
    interpreter = "@python_interpreter//:interpreter",
    python_version = "PY3",
    # https://github.com/bazelbuild/bazel/pull/11434
    # https://github.com/bazelbuild/rules_python/issues/660
    stub_shebang = select({
        # fix macos>=12.3 without python
        "@platforms//os:macos": "#!/usr/bin/env python3",
        "//conditions:default": "",
    }),
    visibility = ["//visibility:public"],
)

honwen avatar Aug 16 '22 02:08 honwen

This issue was automatically closed because it went 30 days without a reply since it was labeled "Can Close?"

github-actions[bot] avatar Oct 10 '22 22:10 github-actions[bot]