Skip to contentSkip to conversation

Moving from Python2 to Python3

Question [email protected] 5 participants 7 messages Mar 25, 2025 – Mar 26, 2025

lore
Share & tools
lore
#0 lore raw

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.

#1 lore raw
Quoted 8 lines · On 2025-03-25 at 15:23:40, [email protected] 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.

Signature · 2 lines
brian m. carlson (they/them)
Toronto, Ontario, CA
#2 lore raw

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.

Quoted 14 lines · brian m. carlson
Quoted 8 lines · On 2025-03-25 at 15:23:40, [email protected] 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.

#3 lore raw
Quoted 8 lines · Nikolay Shustov

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?

#4 lore raw

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").

Quoted 16 lines · Junio C Hamano
Quoted 8 lines · Nikolay Shustov

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?

#5 lore raw
Quoted 9 lines · Nikolay Shustov

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. :)

Signature · 1 line
Todd
#6 lore raw

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

Quoted 30 lines · Todd Zullinger
Quoted 9 lines · Nikolay Shustov

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. :)