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

py_binary always use python as the interpreter when PY3 is specified #200

Closed
mzhaom opened this issue May 21, 2015 · 6 comments
Closed

py_binary always use python as the interpreter when PY3 is specified #200

mzhaom opened this issue May 21, 2015 · 6 comments
Assignees

Comments

@mzhaom
Copy link
Contributor

mzhaom commented May 21, 2015

My build rule:

py_binary(
  name = 'compile_asn',
  srcs = [
    'compile_asn.py'
  ],
  default_python_version = 'PY3',
  srcs_version = 'PY3',
)

I expect the generated wrapper script would use python3 as the interpreter but actual it still uses python:

#!/bin/bash -eu

STUBPATH=$(python -c "import os.path; print os.path.realpath('$0');")
export PYTHONPATH=$STUBPATH.runfiles
python ${PYTHONPATH}/lte/asn/compile_asn.py $@

Is there any way to have some knob to control which python interpreter to use?

mzhaom added a commit to mzhaom/bazel that referenced this issue Jun 11, 2015
PY3 or PY3ONLY is used as the version.

This is needed because /usr/bin/python is an ambigous symlink on most
Linux distrubtions, some distro links it to python2.7, some distro
likes gentoo may link it to python3. Given python2 and python3 are not
fully compatible, we should choose the interpreter explicitly based on
the version specified in py_binary rule.

This should fix issue bazelbuild#200

Change-Id: I6f62b080b795112b1945ada5bb2ad7e58f956c2c
mzhaom added a commit to mzhaom/bazel that referenced this issue Jun 11, 2015
PY3 or PY3ONLY is used as the version.

This is needed because /usr/bin/python is an ambigous symlink on most
Linux distrubtions, some distro links it to python2.7, some distro
likes gentoo may link it to python3. Given python2 and python3 are not
fully compatible, we should choose the interpreter explicitly based on
the version specified in py_binary rule.

This should fix issue bazelbuild#200

Change-Id: I6f62b080b795112b1945ada5bb2ad7e58f956c2c
@hanwen hanwen closed this as completed Jun 15, 2015
@hanwen
Copy link
Contributor

hanwen commented Jun 15, 2015

should be fixed by

@hanwen
Copy link
Contributor

hanwen commented Jun 15, 2015

mzhaom@f08d7fc

@lberki
Copy link
Contributor

lberki commented Nov 24, 2015

I just tried with a small rule:

py_binary(
    name = "a",
    srcs = ["a.py"],
    default_python_version = "PY3",
    srcs_version = "PY3",
)

And it properly exec()s python3. The shebang line is #!/usr/bin/python, though, but that should not influence which Python interpreter the actual binary is executed with. Am I holding it wrong?

@raliste
Copy link

raliste commented Jun 23, 2018

Was the fix merged into bazel? My only workaround is setting the python_path flag to /usr/local/bin/python3

@lberki
Copy link
Contributor

lberki commented Jun 24, 2018

/cc @brandjon

@brandjon
Copy link
Member

brandjon commented Sep 7, 2018

FYI I believe this was fixed and regressed, and is now a dup of #4815.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants