threads / discuss / 63191

[Question] Moving from Python2 to Python3

Subject: [Question] Moving from Python2 to Python3

## tl;dr

7 messages between Mar 25, 2025 and Mar 26, 2025.

replies: 6people: 5as markdown or json

rsbecker@nexbridge.com· Mar 25, 2025, 15:23 UTC · lore
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· Mar 25, 2025, 21:31 UTC · re: rsbecker@nexbridge.com · lore

Re: [Question] Moving from Python2 to Python3

On 2025-03-25 at 15:23:40, rsbecker@nexbridge.com wrote:
Show 8 quoted lines
> 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· Mar 25, 2025, 22:40 UTC · re: brian m. carlson · lore

Re: [Question] Moving from Python2 to Python3

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:
Show 14 quoted lines
> 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· Mar 25, 2025, 23:19 UTC · re: Nikolay Shustov · lore

Re: [Question] Moving from Python2 to Python3

Nikolay Shustov <nikolay.shustov@gmail.com> writes:
Show 8 quoted lines
> 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· Mar 25, 2025, 23:54 UTC · re: Junio C Hamano · lore

Re: [Question] Moving from Python2 to Python3

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:
Show 16 quoted lines
> 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· Mar 26, 2025, 01:02 UTC · re: Nikolay Shustov · lore

Re: [Question] Moving from Python2 to Python3

Nikolay Shustov wrote:
Show 9 quoted lines
> 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· Mar 26, 2025, 01:56 UTC · re: Todd Zullinger · lore

Re: [Question] Moving from Python2 to Python3

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:
Show 30 quoted lines
> 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. :)
>

← back to recent threads