2

I am sure this question has been asked and answered before. I am working with a x64 bit installation of OSGeo4W. I am trying to perform raster calculations using the gdal through the OSGeo4W shell, however every time I try to do the calculation I get the following error:

    C:\>gdal_calc.py -A input1.tif -B input2.tif --outfile=result.tif --calc="A+B"
Traceback (most recent call last):
  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\site.py", line 548, in <module>
    main()
  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\site.py", line 530, in main
    known_paths = addusersitepackages(known_paths)
  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\site.py", line 266, in addusersitepackages
    user_site = getusersitepackages()
  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\site.py", line 241, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\site.py", line 231, in getuserbase
    USER_BASE = get_config_var('userbase')
  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\sysconfig.py", line 516, in get_config_var
    return get_config_vars().get(name)
  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\sysconfig.py", line 449, in get_config_vars
    import re
  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\re.py", line 105, in <module>
    import sre_compile
  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\sre_compile.py", line 14, in <module>
    import sre_parse
  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\sre_parse.py", line 17, in <module>
    from sre_constants import *
  File "C:\PROGRA~1\QGISVA~1\apps\Python27\lib\sre_constants.py", line 18, in <module>
    from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT

I have checked the location for all the required materials, and everything seems to be correct. I have also tried reinstalling the proper gdal python bindings and environmental variables to no avail.

1

OSGeo4W GDAL Python Fix

Step 1. Begin with a fresh install of OSGeo4w, preferably the newest version. This can be downloaded from the following link: http://trac.osgeo.org/osgeo4w/

Step 2. Download and install the version of Python that corresponds to the version of Python used by your installation of OSGeo4W (In this case it is Python 2.7.5). Python installations can be downloaded from the following link: https://www.python.org/

Be sure to choose the correct option between the 32-bit and 64-bit options. The downloaded version of Python must match the downloaded version of OSGeo4W

Step 3. When installing Python, instead of installing in the default directory, navigate to C:\OSGeo4W64\apps\Python27 and install overtop of the version of Python installed with OSGeo4W.

Complete! GDAL Python functionality should work like a charm!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.