Search code examples
pythonpython-3.xenvironment-variables

What is wrong with my python setup? Wrong lib loaded in some cases when multiple versions installed


I think that it is the best to describe my problem with series of prompts. I am missing something, don't know what? How does python3.13 load python 3.11 libs???

Solutions like delete other versions and similar are not good. I want to fix it as it is.

C:\Temp\2025\01\python_ver_check (master) >where python
C:\Program Files\Python313\python.exe
C:\Program Files\Python311\python.exe
C:\OSGeo4W\bin\python.exe
C:\Users\UserName\AppData\Local\Microsoft\WindowsApps\python.exe

C:\Temp\2025\01\python_ver_check (master) >python --version
Python 3.13.1

C:\Temp\2025\01\python_ver_check (master) >type globaj.py
import glob

for g in glob.glob('*'):
    print(g)
C:\Temp\2025\01\python_ver_check (master) >globaj.py
Traceback (most recent call last):
  File "C:\Temp\2025\01\python_ver_check\globaj.py", line 1, in <module>
    import glob
  File "C:\Program Files\Python313\Lib\glob.py", line 5, in <module>
    import re
  File "C:\Program Files\Python313\Lib\re\__init__.py", line 126, in <module>
    from . import _compiler, _parser
  File "C:\Program Files\Python313\Lib\re\_compiler.py", line 18, in <module>
    assert _sre.MAGIC == MAGIC, "SRE module mismatch"
           ^^^^^^^^^^^^^^^^^^^
AssertionError: SRE module mismatch

C:\Temp\2025\01\python_ver_check (master) >python globaj.py
globaj.py
net48
net8

C:\Temp\2025\01\python_ver_check (master) >assoc .py
.py=Python.File

C:\Temp\2025\01\python_ver_check (master) >ftype Python.File
Python.File="C:\WINDOWS\py.exe" "%L" %*

C:\Temp\2025\01\python_ver_check (master) >py --version
Python 3.13.1

C:\Temp\2025\01\python_ver_check (master) >echo %PATH%
C:\Program Files\Python313\Scripts\;C:\Program Files\Python313\;C:\Program Files (x86)\Common Files\Oracle\Java\java8path;...

Solution

  • PYTHONHOME was bad! Never knew this variable is used also, only looked at PATH

    echo %PYTHONHOME%
    C:\Program Files\Python311
    

    Stil not sure why python globaj.py worked while globay.py alone didn't.