1

I normally use my Python script using OSGeo4W64 command shell on my 64-bit PC (Windows10). Now, I'm trying to use my script on a 32-bit machine (Windows10). In the 32-bit machine, there's an issue with importing the from osgeo import osr module.

I used the Advanced installer to install OsGeo4W shell. I installed all default modules except the 'setuptools' module (which is not installed by default and so I installed it).

In one of my Python files, I have the following (note the "EnvSettings" module I made):

import sys
import os
import math
import csv
import EnvSettings

from osgeo import osr

In EnvSettings, I have:

import os
path = os.environ['PATH']
pgdal= 'C:\\OSGeo4W64\\share\\gdal;'
os.environ['GDAL_DATA']='C:\\OSGeo4W64\\share\\gdal'
os.environ['GDAL_DRIVER_PATH']='C:\\OSGeo4W64\\share\\gdal\\gdalplugins'
os.environ['PROJ_LIB']='C:\\OSGeo4W64\\share\\gdal\\projlib'
os.environ['PATH'] = "%s;%s" % (pgdal, path)

And this is the output:

Traceback (most recent call last):
  File "ols_engine.py", line 5, in <module>
    import mdl
  File "C:\OSGeo4W\PyPack\v0.2_cells_op\mdl.py", line 8, in <module>
    import osr
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\osr.py", line 2, in <module>
    from osgeo.gdal import deprecation_warn
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\osgeo\__init__.py", line 21, in <module>
    _gdal = swig_import_helper()
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\osgeo\__init__.py", line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: DLL load failed: The specified module could not be found.

I also tried:

import os
path = os.environ['PATH']
pgdal= 'C:\\OSGeo4W\\share\\gdal;'
os.environ['GDAL_DATA']='C:\\OSGeo4W\\share\\gdal'
os.environ['GDAL_DRIVER_PATH']='C:\\OSGeo4W\\share\\gdal\\gdalplugins'
os.environ['PROJ_LIB']='C:\\OSGeo4W\\share\\gdal\\projlib'
os.environ['PATH'] = "%s;%s" % (pgdal, path)

And this is the output:

Traceback (most recent call last):
  File "ols_engine.py", line 5, in <module>
    import mdl
  File "C:\OSGeo4W\PyPack\v0.2_cells_op\mdl.py", line 8, in <module>
    import osr
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\osr.py", line 2, in <module>
    from osgeo.gdal import deprecation_warn
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\osgeo\__init__.py", line 21, in <module>
    _gdal = swig_import_helper()
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\osgeo\__init__.py", line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: DLL load failed: The specified module could not be found.

When I just use Python from the shell, I tried:

C:\OSGeo4W\PyPack\v0.2_cells_op>python
Python 2.7.4 (default, Apr  6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import osr
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\osr.py", line 2, in <module>
    from osgeo.gdal import deprecation_warn
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\osgeo\__init__.py", line 21, in <module>
    _gdal = swig_import_helper()
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\osgeo\__init__.py", line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: DLL load failed: The specified module could not be found.
>>> import osgeo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\osgeo\__init__.py", line 21, in <module>
    _gdal = swig_import_helper()
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\osgeo\__init__.py", line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: DLL load failed: The specified module could not be found.
>>> from osgeo import osr
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\osgeo\__init__.py", line 21, in <module>
    _gdal = swig_import_helper()
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\osgeo\__init__.py", line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: DLL load failed: The specified module could not be found.

And also:

ImportError: DLL load failed: The specified module could not be found.
>>> import EnvSettings
>>> import osr
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\osr.py", line 2, in <module>
    from osgeo.gdal import deprecation_warn
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\osgeo\__init__.py", line 21, in <module>
    _gdal = swig_import_helper()
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\osgeo\__init__.py", line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: DLL load failed: The specified module could not be found.
>>> import osgeo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\osgeo\__init__.py", line 21, in <module>
    _gdal = swig_import_helper()
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\osgeo\__init__.py", line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: DLL load failed: The specified module could not be found.
>>> from osgeo import osr
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\osgeo\__init__.py", line 21, in <module>
    _gdal = swig_import_helper()
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\osgeo\__init__.py", line 17, in swig_import_helper
    _mod = imp.load_module('_gdal', fp, pathname, description)
ImportError: DLL load failed: The specified module could not be found.
>>>

I struggle with understanding how to set environments. Can someone please provide some direction to make the osgeo and osr module work?

1 Answer 1

1

I fixed it. The problem was when I installed OSGEO4W on this machine, I changed the local package directory.

See below

It was originally set to some other folder I can't remember what it was. But the problem was when I reset it to "c:\". Then I set it to "C:\OSGeo4W". This seemed to have fixed the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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