threads / discuss / 62908

`git p4` broken on machines which do not have python on path

Subject: `git p4` broken on machines which do not have python on path

## tl;dr

5 messages between Feb 6, 2025 and Feb 6, 2025.

replies: 4people: 4as markdown or json

Kapil Somani· Feb 6, 2025, 01:27 UTC · lore

Thank you for filling out a Git bug report! Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue) Run `git p4 clone //path/to/p4/depot --destination=/tmp/localcopy`

What did you expect to happen? (Expected behavior) The command should have imported perforce depot to a git repository

What happened instead? (Actual behavior) The command threw error fatal: 'p4' appears to be a git command, but we were not able to execute it. Maybe git-p4 is broken?

What's different between what you expected and what actually happened? The command did not perform desired operation

Anything else you want to add: The machine does not have python on path I noticed `git-p4`'s shebang line points to python. On my local git installation, i was able to update shebang line on git-p4 to python3 and the command worked as expected. With python3 now being default should be update git-p4 to run using python3 ?

Please review the rest of the bug report below. You can delete any lines you don't wish to share.

[System Info] git version: git version 2.30.2 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Linux 5.10.0-33-amd64 #1 SMP Debian 5.10.226-1 (2024-10-03) x86_64 compiler info: gnuc: 10.2 libc info: glibc: 2.31 $SHELL (typically, interactive shell): /bin/tcsh

[Enabled Hooks] not run from a git repository - no hooks to show

brian m. carlson· Feb 6, 2025, 01:46 UTC · re: Kapil Somani · lore

Re: `git p4` broken on machines which do not have python on path

On 2025-02-06 at 01:27:48, Kapil Somani wrote:
Show 15 quoted lines
> Thank you for filling out a Git bug report!
> Please answer the following questions to help us understand your issue.
> 
> What did you do before the bug happened? (Steps to reproduce your issue)
> Run `git p4 clone //path/to/p4/depot --destination=/tmp/localcopy`
> 
> 
> What did you expect to happen? (Expected behavior)
> The command should have imported perforce depot to a git repository
> 
> 
> What happened instead? (Actual behavior)
> The command threw error
> fatal: 'p4' appears to be a git command, but we were not
> able to execute it. Maybe git-p4 is broken?

Can you mention where you got your version of Git from? Is this a Debian Git, one you compiled yourself, or another one entirely?

Show 11 quoted lines
> What's different between what you expected and what actually happened?
> The command did not perform desired operation
> 
> 
> Anything else you want to add:
> The machine does not have python on path
> I noticed `git-p4`'s shebang line points to python.
> On my local git installation, i was able to update shebang line on
> git-p4 to python3 and
> the command worked as expected.
> With python3 now being default should be update git-p4 to run using python3 ?

I think if you compiled this yourself, you probably need to set PYTHON_PATH to a suitable Python when running the Makefile, and that will rewrite the shebang. If you got this from another source, then they should have compiled the package with a suitable PYTHON_PATH and depended on an appropriate version of Python.

I realize that Python 3 is now the default, but there were apparently still some people who want to use Python 2.7 last time this came up, so the default shebang hasn't changed. According to Python upstream, `python` can be of any version, although for all distros I'm aware of, `python` is always version 2.

-- 
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA
Illia Bobyr· Feb 6, 2025, 02:16 UTC · re: brian m. carlson · lore

Re: `git p4` broken on machines which do not have python on path

On 2/5/25 17:46, brian m. carlson wrote:
Show 5 quoted lines
> I realize that Python 3 is now the default, but there were apparently
> still some people who want to use Python 2.7 last time this came up, so
> the default shebang hasn't changed. According to Python upstream,
> `python` can be of any version, although for all distros I'm aware of,
> `python` is always version 2.
I just checked my Ubuntu 24.10 and `python` is `python3`.

❯ python --version Python 3.12.7

❯ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description:    Ubuntu 24.10 Release:        24.10 Codename:       oracular

❯ whereis python python: /usr/bin/python

❯ dpkg -S /usr/bin/python python-is-python3: /usr/bin/python

There are both `python-is-python2` and `python-is-python3` packages. They just provide a symlink for convenience. And one can use Python version managers to manage what `python` means, of cause.

brian m. carlson· Feb 6, 2025, 22:18 UTC · lore

Re: `git p4` broken on machines which do not have python on path

On 2025-02-06 at 02:12:02, Kapil Somani wrote:
Show 9 quoted lines
> Thanks for quick response Brian
> 
> Yes, our team compiles git for use within our organization.
> I'll reach out to them and see if they can provide path during build.
> 
> Meanwhile, I was able to update copy of the git (compiled by my team) to
> use python3 on shebang line.
> It appears that the git-p4 is compatible with Python3. Is git team planning
> to update it near future?
It's my understanding that it's designed to work with both Python 2 and
3.  It's unlikely that the shebang will be updated until it's no longer
guaranteed to work with Python 2, since `python` is more generic than
`python3`.  When that is, I don't know, since I don't use Perforce and
don't maintain git-p4, which has a separate maintainer.
-- 
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA
Junio C Hamano· Feb 6, 2025, 23:17 UTC · re: brian m. carlson · lore

Re: `git p4` broken on machines which do not have python on path

"brian m. carlson" <sandals@crustytoothpaste.net> writes:
Show 13 quoted lines
> On 2025-02-06 at 02:12:02, Kapil Somani wrote:
>> Thanks for quick response Brian
>> 
>> Yes, our team compiles git for use within our organization.
>> I'll reach out to them and see if they can provide path during build.
>> 
>> Meanwhile, I was able to update copy of the git (compiled by my team) to
>> use python3 on shebang line.
>> It appears that the git-p4 is compatible with Python3. Is git team planning
>> to update it near future?
>
> It's my understanding that it's designed to work with both Python 2 and
> 3.  It's unlikely that the shebang will be updated until it's no longer

Correct. The CI has jobs to try git-p4 with both python2 and python3 since Mar 2020.

> guaranteed to work with Python 2, since `python` is more generic than
> `python3`.  When that is, I don't know, since I don't use Perforce and
> don't maintain git-p4, which has a separate maintainer.
I am not sure what story about shebang is discussed here.

If the complaint is "your script says '/usr/bin/env python', but my users don't have 'python' on their $PATH", I think that is barking up a wrong tree. As a general principle, we try not to rely on "env".

Just like other scripts, we munge git-p4.py script to replace the shebang line to use the path to the python binary specified by the builder into resulting git-p4 "executable" file that is installed.

We do this (not specifically for git-p4 but as a general principle) because we do not want to get affected by random customized versions of stuff end-users install on their $PATH that overrides the ones from the system that builders determined to be used by Git.

Is the complaint that "on my system there are /usr/bin/python2 and /usr/bin/python3 but no vanilla /usr/bin/python installed"?

So it is your responsibility to tell the build procedure that you want to use "/usr/bin/python3", as the build procedure defaults to "/usr/bin/python" when you do not specify any.

← back to recent threads