# [Question] Moving from Python2 to Python3

7 messages from 2025-03-25 to 2025-03-26. Participants: rsbecker@nexbridge.com, brian m. carlson, Nikolay Shustov, Junio C Hamano, Todd Zullinger.
Thread: https://gitlist.dev/t/63191

## rsbecker@nexbridge.com, 2025-03-25 15:23

Subject: [Question] Moving from Python2 to Python3
Message-ID: <022b01db9d99$e68785c0$b3969140$@nexbridge.com>
URL: https://gitlist.dev/e/022b01db9d99%24e68785c0%24b3969140%24%40nexbridge.com

```
Hi Git Team,

I have Python2 and Python3 on my system. We are deprecating Python2 ASAP. Is
there an easy way to force git
to use Python3 only? Both are in /usr/bin. python has a symbolic link to
python2 right now, but we are probably
going to change that. I already have modified settings in config.mak.uname
PYTHON_PATH = /usr/bin/python3.

Thanks,
Randall

--
Brief whoami: NonStop&UNIX developer since approximately
UNIX(421664400)
NonStop(211288444200000000)
-- In real life, I talk too much.



```

## brian m. carlson, 2025-03-25 21:31

Subject: Re: [Question] Moving from Python2 to Python3
Message-ID: <Z-MgpuxFQ3xEgvsU@tapette.crustytoothpaste.net>
URL: https://gitlist.dev/e/Z-MgpuxFQ3xEgvsU%40tapette.crustytoothpaste.net
In-Reply-To: <022b01db9d99$e68785c0$b3969140$@nexbridge.com>

```
On 2025-03-25 at 15:23:40, rsbecker@nexbridge.com wrote:
> Hi Git Team,
> 
> I have Python2 and Python3 on my system. We are deprecating Python2 ASAP. Is
> there an easy way to force git
> to use Python3 only? Both are in /usr/bin. python has a symbolic link to
> python2 right now, but we are probably
> going to change that. I already have modified settings in config.mak.uname
> PYTHON_PATH = /usr/bin/python3.

I think only git-p4 uses Python in our codebase, so changing `PYTHON_PATH`
should be sufficient to fix it.  As far as I know, git-p4 currently
supports both, so things should just work.

Of course, I might be mistaken, since I don't use git-p4.
-- 
brian m. carlson (they/them)
Toronto, Ontario, CA

```

## Nikolay Shustov, 2025-03-25 22:40

Subject: Re: [Question] Moving from Python2 to Python3
Message-ID: <66e39a95-09a3-44dc-ac71-a6c02b5949c9@gmail.com>
URL: https://gitlist.dev/e/66e39a95-09a3-44dc-ac71-a6c02b5949c9%40gmail.com
In-Reply-To: <Z-MgpuxFQ3xEgvsU@tapette.crustytoothpaste.net>

```
git-p4 is designed to work both with Python 2 and Python 3.

However, changing just PYTHONPATH may not to be good enough.

In general, it is necessary to make having PYTHONPATH value and the 
version of Python executable which application is run by, to be 
coherent: Python executable has to be able to work correctly with the 
libraries PYTHONPATH points to.

How to achieve it - depends on the OS where git-p4 is run.

If used from *nix like shells, git-p4 would be using Python executable 
from the shebang in the beginning of the file: #!/usr/bin/python .
On Windows, it is possible that the specific Python executable could be 
associated with .py files so that shebang maybe not in play at all.

Some OSes may require manual adjustments such as setting PYTHONPATH 
shell profile (environment variables, for Windows) and ensuring proper 
Python executable will be put in PATH. Some (Linux) may use 
update-alternatives commands to switch between Python (and other 
applications) versions easier. If it is desired to keep default Python 
of one version and run git-p4 with another, more tweaks/hackery may be 
needed.

I would recommend to refer to the documentation on the specific OS and 
also look for hints in Python related online documentation/forums.

On 3/25/25 17:31, brian m. carlson wrote:
> On 2025-03-25 at 15:23:40, rsbecker@nexbridge.com wrote:
>> Hi Git Team,
>>
>> I have Python2 and Python3 on my system. We are deprecating Python2 ASAP. Is
>> there an easy way to force git
>> to use Python3 only? Both are in /usr/bin. python has a symbolic link to
>> python2 right now, but we are probably
>> going to change that. I already have modified settings in config.mak.uname
>> PYTHON_PATH = /usr/bin/python3.
> I think only git-p4 uses Python in our codebase, so changing `PYTHON_PATH`
> should be sufficient to fix it.  As far as I know, git-p4 currently
> supports both, so things should just work.
>
> Of course, I might be mistaken, since I don't use git-p4.

```

## Junio C Hamano, 2025-03-25 23:19

Subject: Re: [Question] Moving from Python2 to Python3
Message-ID: <xmqqtt7glmut.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqtt7glmut.fsf%40gitster.g
In-Reply-To: <66e39a95-09a3-44dc-ac71-a6c02b5949c9@gmail.com>

```
Nikolay Shustov <nikolay.shustov@gmail.com> writes:

> git-p4 is designed to work both with Python 2 and Python 3.
>
> However, changing just PYTHONPATH may not to be good enough.
>
> In general, it is necessary to make having PYTHONPATH value and the
> version of Python executable which application is run by, to be
> coherent: Python executable has to be able to work correctly with the
> libraries PYTHONPATH points to.

Hmph, but isn't that the core competence of those who package Python
to their target system?  If we run something with /usr/bin/python3,
without any strange customization, that binary ought to know where
it should pull its associated standard library files from, and we as
the language users do not have to worry about it, no?


```

## Nikolay Shustov, 2025-03-25 23:54

Subject: Re: [Question] Moving from Python2 to Python3
Message-ID: <6977f08e-3c49-4bcc-9ab7-e3cc61a78396@gmail.com>
URL: https://gitlist.dev/e/6977f08e-3c49-4bcc-9ab7-e3cc61a78396%40gmail.com
In-Reply-To: <xmqqtt7glmut.fsf@gitster.g>

```
You are right, my answer was over-engineered.
Instead of speculating about what else needs to be done if one decides 
to set PYTHONPATH, I should have just advised to use the OS specific 
method on setting up the "default" Python as Python3 and be with it.
Well, unless the dual Python is needed (git-p4 running with the Python 
different from system "default").

On 3/25/25 19:19, Junio C Hamano wrote:
> Nikolay Shustov <nikolay.shustov@gmail.com> writes:
>
>> git-p4 is designed to work both with Python 2 and Python 3.
>>
>> However, changing just PYTHONPATH may not to be good enough.
>>
>> In general, it is necessary to make having PYTHONPATH value and the
>> version of Python executable which application is run by, to be
>> coherent: Python executable has to be able to work correctly with the
>> libraries PYTHONPATH points to.
> Hmph, but isn't that the core competence of those who package Python
> to their target system?  If we run something with /usr/bin/python3,
> without any strange customization, that binary ought to know where
> it should pull its associated standard library files from, and we as
> the language users do not have to worry about it, no?
>

```

## Todd Zullinger, 2025-03-26 01:02

Subject: Re: [Question] Moving from Python2 to Python3
Message-ID: <Z-NSGtV06NPE_C9D@teonanacatl.net>
URL: https://gitlist.dev/e/Z-NSGtV06NPE_C9D%40teonanacatl.net
In-Reply-To: <6977f08e-3c49-4bcc-9ab7-e3cc61a78396@gmail.com>

```
Nikolay Shustov wrote:
> You are right, my answer was over-engineered.
>
> Instead of speculating about what else needs to be done if
> one decides to set PYTHONPATH, I should have just advised
> to use the OS specific method on setting up the "default"
> Python as Python3 and be with it.
>
> Well, unless the dual Python is needed (git-p4 running
> with the Python different from system "default").

Perhaps you were conflating PYTHON_PATH, which brian
suggested, with PYTHONPATH?

PYTHON_PATH is used by the git build system to set the path
to the python executable, e.g.: /usr/bin/python2,
/usr/bin/python3, etc.

PYTHONPATH is used by python itself to point to the
location(s) of module files, similar to PATH, as you
mentioned.

The Fedora distribution packaging set PYTHON_PATH to python2
or python3 while both were available and things worked well.
Only python3 is supported now, and PYTHON_PATH is set
accordingly.

That ought to work just as well for NonStop.  If it doesn't,
that would most likely be something to take up with the OS
folks handling python3. :)

-- 
Todd

```

## Nikolay Shustov, 2025-03-26 01:56

Subject: Re: [Question] Moving from Python2 to Python3
Message-ID: <77b5fa59-a8a1-4859-8f3d-41f94fa8120d@gmail.com>
URL: https://gitlist.dev/e/77b5fa59-a8a1-4859-8f3d-41f94fa8120d%40gmail.com
In-Reply-To: <Z-NSGtV06NPE_C9D@teonanacatl.net>

```
Doh! Of course I thought of PYTHONPATH not of PYTHON_PATH.
My apologies for the noise.

On 3/25/25 21:02, Todd Zullinger wrote:
> Nikolay Shustov wrote:
>> You are right, my answer was over-engineered.
>>
>> Instead of speculating about what else needs to be done if
>> one decides to set PYTHONPATH, I should have just advised
>> to use the OS specific method on setting up the "default"
>> Python as Python3 and be with it.
>>
>> Well, unless the dual Python is needed (git-p4 running
>> with the Python different from system "default").
> Perhaps you were conflating PYTHON_PATH, which brian
> suggested, with PYTHONPATH?
>
> PYTHON_PATH is used by the git build system to set the path
> to the python executable, e.g.: /usr/bin/python2,
> /usr/bin/python3, etc.
>
> PYTHONPATH is used by python itself to point to the
> location(s) of module files, similar to PATH, as you
> mentioned.
>
> The Fedora distribution packaging set PYTHON_PATH to python2
> or python3 while both were available and things worked well.
> Only python3 is supported now, and PYTHON_PATH is set
> accordingly.
>
> That ought to work just as well for NonStop.  If it doesn't,
> that would most likely be something to take up with the OS
> folks handling python3. :)
>

```
