Bug report #18413

Incorrect Python ver. with GDAL Merge tool in QGIS 3

Added by Joe Krienert about 6 years ago. Updated almost 6 years ago.

Status:Closed
Priority:High
Assignee:Joe Krienert
Category:Processing/GDAL
Affected QGIS version:3.0.0 Regression?:Yes
Operating System:Windows 10 64bit Easy fix?:No
Pull Request or Patch supplied:No Resolution:up/downstream
Crashes QGIS or corrupts data:No Copied to github as #:26302

Description

Used OSGeo4W64 installer for QGIS 3 and friends. Made sure GDAL libs were included.
When running GDAL Merge tool an error is raised similar to #17298
Adding...

python --version

... to the gdal_merge.bat indicates it is trying to use 2.7.5.


Related issues

Duplicates QGIS Application - Bug report #17298: Processing: gdal merge python error on QGIS 3 Closed 2017-10-17

History

#1 Updated by Joe Krienert about 6 years ago

Error output:

2018-03-11T19:56:08    INFO    cmd.exe /C  gdal_merge.bat -pct -ot Float32 -of GTiff -o "C:/Users/Joe M. Krienert/Desktop/Output.tif" C:/Users/Joe M. Krienert/Desktop/ned03m37089a1.tif C:/Users/Joe M. Krienert/Desktop/ned03m37089b2.tif
2018-03-11T19:56:08    INFO    GDAL execution console output
            Python 2.7.5
            File "C:\OSGEO4~1\apps\Python36\lib\site.py", line 177
                  file=sys.stderr)
                    ^
            SyntaxError: invalid syntax

#2 Updated by Giovanni Manghi about 6 years ago

  • Category changed from GDAL Tools to Processing/GDAL
  • Status changed from Open to Feedback
  • Regression? changed from No to Yes

So the error does not seems related to the python version, right?

#3 Updated by Joe Krienert about 6 years ago

Should GDAL be using Python version 3.6 in QGIS 3? If so, then the Python version might be the problem. If not, then there might be something astray in the basic OSGeo4W64 installer?

#4 Updated by Giovanni Manghi about 6 years ago

Joe Krienert wrote:

Should GDAL be using Python version 3.6 in QGIS 3? If so, then the Python version might be the problem. If not, then there might be something astray in the basic OSGeo4W64 installer?

yes, qgis 3 uses python 3.

#5 Updated by Joe Krienert about 6 years ago

When opening the Python terminal plugin in QGIS 3 desktop and import/calling print (sys.version), the ver. stated is Python 3.
Could the GDAL merge error be associated with conflicting syntax of attempting to run Python 3 commands in a Python 2.7 environment?

#6 Updated by Joe Krienert about 6 years ago

Python 2.7.5
File "C:\OSGEO4~1\apps\Python36\lib\site.py", line 177
      file=sys.stderr)
       ^
      Syntax Error: invalid syntax

Does this code snippet from the GDAL merge tool log suggest a conflict between the library (Python36) and active Python version (2.7.5)?

Seems anomolous that the Python plugin terminal tells Python 3 as the active version, but the processing tool call to GDAL states ver 2.7.5.

Does GDAL not support Python 3?

#7 Updated by Joe Krienert about 6 years ago

This test suggest that GDAL is switching the active python version from v. 3.6 to 2.7.

From a freshly opened (as admin) OSGeo4W shell...

Check the current ver. of Python in use:

C:\Windows\System32>python --version
Python 2.7.5

Oddly set to ver. 2.7.5, update to ver. 3 environment:

C:\Windows\System32>gdal-dev-py3-env
C:\Windows\System32>call gdal-dev-env.bat
C:\Windows\System32>SET GDAL_DATA=C:\OSGEO4~1\apps\gdal-dev\share\gdal
C:\Windows\System32>SET GDAL_DRIVER_PATH=C:\OSGEO4~1\apps\gdal-dev\bin\gdalplugins
C:\Windows\System32>PATH C:\OSGEO4~1\apps\gdal-dev\bin;C:\OSGEO4~1\apps\Python36\Scripts;C:\OSGEO4~1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBem;C:\OSGEO4~1\apps\msys\bin
C:\Windows\System32>call py3_env.bat
C:\Windows\System32>SET PYTHONPATH=
C:\Windows\System32>SET PYTHONHOME=C:\OSGEO4~1\apps\Python36
C:\Windows\System32>PATH C:\OSGEO4~1\apps\Python36;C:\OSGEO4~1\apps\Python36\Scripts;C:\OSGEO4~1\apps\gdal-dev\bin;C:\OSGEO4~1\apps\Python36\Scripts;C:\OSGEO4~1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBem;C:\OSGEO4~1\apps\msys\bin
C:\Windows\System32>SET PYTHONPATH=C:\OSGEO4~1\apps\gdal-dev\pymod3\lib\site-packages;
C:\Windows\System32>PATH C:\OSGEO4~1\apps\gdal-dev\pymod3\scripts;C:\OSGEO4~1\apps\Python36;C:\OSGEO4~1\apps\Python36\Scripts;C:\OSGEO4~1\apps\gdal-dev\bin;C:\OSGEO4~1\apps\Python36\Scripts;C:\OSGEO4~1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBem;C:\OSGEO4~1\apps\msys\bin

Verify environment ver. changed:

C:\Windows\System32>python --version
Python 3.6.0

Attempt GDAL merge:

C:\Windows\System32>gdal_merge.bat -pct -ot Float32 -of GTiff -o "C:/Users/Joe/Desktop/OUTPUT.tif" D:/Personal/ned03m37089a1.tif D:/Personal/ned03m37089a2.tif
  File "C:\OSGEO4~1\apps\Python36\lib\site.py", line 177
    file=sys.stderr)
        ^
SyntaxError: invalid syntax

Double check Python environment ver:

C:\Windows\System32>python --version
Python 2.7.5

Why would calling GDAL merge reset the python environment ver?

#8 Updated by Jürgen Fischer about 6 years ago

  • Description updated (diff)

#9 Updated by Jürgen Fischer about 6 years ago

#10 Updated by Nyall Dawson almost 6 years ago

  • Resolution set to up/downstream
  • Status changed from Feedback to Closed

This was fixed upstream in osgeo4w

Also available in: Atom PDF