Skip to content

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

Closed
@nishantc1527

Description

@nishantc1527

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.

Activity

tesuji

tesuji commented on Aug 2, 2020

@tesuji
Contributor

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

Mark-Simulacrum

Mark-Simulacrum commented on Aug 2, 2020

@Mark-Simulacrum
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

mati865 commented on Aug 2, 2020

@mati865
Member

@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

K900 commented on Aug 2, 2020

@K900

#!/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

mati865 commented on Aug 2, 2020

@mati865
Member

@K900 Rust supports both Python 2 and Python 3.

nishantc1527

nishantc1527 commented on Aug 2, 2020

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

RalfJung commented on Aug 7, 2020

@RalfJung
Member

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

K900 commented on Aug 7, 2020

@K900

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 $@
added
T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
on Aug 8, 2020
jyn514

jyn514 commented on Aug 18, 2020

@jyn514
Member

Closing as duplicate of #71818

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @RalfJung@K900@mati865@Mark-Simulacrum@tesuji

        Issue actions

          On Linux, You Have To Manually Change The Shebang On x.py From Python To Python3 · Issue #75034 · rust-lang/rust