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

On Linux, You Have To Manually Change The Shebang On x.py From Python To Python3 #75034

Closed
nishantc1527 opened this issue Aug 2, 2020 · 9 comments
Labels
T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@nishantc1527
Copy link

nishantc1527 commented Aug 2, 2020

Currently, this is the first line in x.py.

#!/usr/bin/env python

However, on linux since it is python3 by default when you install python (at least on centos), I have to manually change it to this every time I clone this repository.

#!/usr/bin/env python3

Is there some way that there is an automated way to detect this? If not, maybe you can update the docs because it took me a while to figure out what was going wrong.

@tesuji
Copy link
Contributor

tesuji commented Aug 2, 2020

Do you mean that by default CentOS use python as python3?

@Mark-Simulacrum
Copy link
Member

There is unfortunately not a universal python shebang - windows never has python3 IIRC, and Ubuntu at least doesn't by default have a python these days.

If you have concrete proposals on how to make this work, I would love to hear them - a compiler team MCP is the way to go to propose such a change.

@mati865
Copy link
Contributor

mati865 commented Aug 2, 2020

@nishantc1527 You can either use python3 x.py or set python3 as the default version using this official guide: https://developers.redhat.com/blog/2018/11/14/python-in-rhel-8/

@K900
Copy link

K900 commented Aug 2, 2020

#!/usr/bin/env python3 should be a universal shebang for Python 3 specifically - I'm not aware of any distributions that actively remove the python3 symlink, and the Windows launcher understands it as well.

@mati865
Copy link
Contributor

mati865 commented Aug 2, 2020

@K900 Rust supports both Python 2 and Python 3.

@nishantc1527
Copy link
Author

If there isn't an automated way to detect this (at least I can't thing of anything), then can the team update the documentation on how to install rust from source? It took me a while to figure out what was happening, and I believe someone smarter than me (which includes a lot of people) can get confused to.

@RalfJung
Copy link
Member

RalfJung commented Aug 7, 2020

Cc #71818: latest Ubuntu also does not have python any more by default, it seems.

So longer-term, I think it is clear that this should become python3 eventually, as more and more distros no longer install Python 2 by default. The question is when is the right time for Rust to switch its shebang.

@K900
Copy link

K900 commented Aug 7, 2020

An alternative option would be to provide some sort of a wrapper script (./x.sh?) that effectively just does

PYTHON=`which python3 || which python2 || which python` 2>/dev/null
"${PYTHON}" ./x.py $@

@jyn514 jyn514 added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Aug 8, 2020
@jyn514
Copy link
Member

jyn514 commented Aug 18, 2020

Closing as duplicate of #71818

@jyn514 jyn514 closed this as completed Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

No branches or pull requests

7 participants