1
2
3
4 from sys import platform, version_info
5 if version_info >= (3, 8, 0) and platform == 'win32':
6 import os
7 if 'USE_PATH_FOR_GDAL_PYTHON' in os.environ and 'PATH' in os.environ:
8 for p in os.environ['PATH'].split(';'):
9 if p:
10 os.add_dll_directory(p)
11
12 if version_info >= (2, 7, 0):
14 import importlib
15 from os.path import dirname, basename
16 mname = basename(dirname(__file__)) + '._gdal'
17 try:
18 return importlib.import_module(mname)
19 except ImportError as e:
20 if version_info >= (3, 8, 0) and platform == 'win32':
21 import os
22 if not 'USE_PATH_FOR_GDAL_PYTHON' in os.environ:
23 msg = 'On Windows, with Python >= 3.8, DLLs are no longer imported from the PATH.\n'
24 msg += 'If gdalXXX.dll is in the PATH, then set the USE_PATH_FOR_GDAL_PYTHON=YES environment variable\n'
25 msg += 'to feed the PATH into os.add_dll_directory().'
26
27 import sys
28 import traceback
29 traceback_string = ''.join(traceback.format_exception(*sys.exc_info()))
30 raise ImportError(traceback_string + '\n' + msg)
31 return importlib.import_module('_gdal')
32 _gdal = swig_import_helper()
33 del swig_import_helper
34 elif version_info >= (2, 6, 0):
36 from os.path import dirname
37 import imp
38 fp = None
39 try:
40 fp, pathname, description = imp.find_module('_gdal', [dirname(__file__)])
41 except ImportError:
42 import _gdal
43 return _gdal
44 if fp is not None:
45 try:
46 _mod = imp.load_module('_gdal', fp, pathname, description)
47 except ImportError as e:
48 if version_info >= (3, 8, 0) and platform == 'win32':
49 import os
50 if not 'USE_PATH_FOR_GDAL_PYTHON' in os.environ:
51 msg = 'On Windows, with Python >= 3.8, DLLs are no longer imported from the PATH.\n'
52 msg += 'If gdalXXX.dll is in the PATH, then set the USE_PATH_FOR_GDAL_PYTHON=YES environment variable\n'
53 msg += 'to feed the PATH into os.add_dll_directory().'
54
55 import sys
56 import traceback
57 traceback_string = ''.join(traceback.format_exception(*sys.exc_info()))
58 raise ImportError(traceback_string + '\n' + msg)
59 raise
60 finally:
61 fp.close()
62 return _mod
63 _gdal = swig_import_helper()
64 del swig_import_helper
65 else:
66 import _gdal
67
68 __version__ = _gdal.__version__ = _gdal.VersionInfo("RELEASE_NAME")
69