Part 1:
These pages mention the No module named 'ogr'
problem:
I searched my C dirve for ogr.py
and gdal.py
. In those files, I tried replacing import ogr
with import osgeo.ogr
. I did it in gdal.py
in two places: C:\Users\<my_user>\anaconda3\pkgs\gdal-3.4.1-py39h9b7a543_0\Lib\site-packages\osgeo
.
But in ogr.py
, I couldn't find any references to import ogr
.
I also changed import ogr
to import osgeo.ogr
in GDBee: C:\GDBee-master\GDBee-master\src\geodatabase.py
.
I tried to run GDBee again. It got past the ModuleNotFoundError: No module named 'ogr'
error this time. But now it has a different error:
~\anaconda3\lib\site-packages\osgeo\__init__.py in swig_import_helper()
39 import traceback
40 traceback_string = ''.join(traceback.format_exception(*sys.exc_info()))
---> 41 raise ImportError(traceback_string + '\n' + msg)
42 return importlib.import_module('_gdal')
43
ImportError: Traceback (most recent call last):
File "C:\Users\<user>\anaconda3\lib\site-packages\osgeo\__init__.py", line 29, in swig_import_helper
return importlib.import_module(mname)
File "C:\Users\<user>\anaconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
File "<frozen importlib._bootstrap>", line 565, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 1173, in create_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
ImportError: DLL load failed while importing _gdal: The specified module could not be found.
On Windows, with Python >= 3.8, DLLs are no longer imported from the PATH.
If gdalXXX.dll is in the PATH, then set the USE_PATH_FOR_GDAL_PYTHON=YES environment variable
to feed the PATH into os.add_dll_directory().
Part 2:
Regarding the answer from @FelipeGutierrez on this page: Stack Overflow: No module named ogr.
I followed the non-pip instructions in @Felipe‘s option 1.).
1.) Download the Installer for the GDAL python bindings (requires to install the GDAL core)
msi, and install.
Open cmd and type:
setx PATH "%PATH%;C:\Program Files (x86)\GDAL"
setx PATH "%GDAL_DATA%;C:\Program Files (x86)\GDAL\gdal-data"
setx PATH "%GDAL_DRIVER_PATH%;C:\Program Files (x86)\GDAL\gdalplugins"
*Note that each one of the commands above is a separate one, so copy-paste and enter, each one separately. If you downloaded the x64
version just remove the (x86).
My steps:
setx PATH "%PATH%;C:\Program Files\GDAL"
setx PATH "%GDAL_DATA%;C:\Program Files\GDAL\gdal-data"
setx PATH "%GDAL_DRIVER_PATH%;C:\Program Files\GDAL\gdalplugins"
Now, when I try to run GDBee from Qt
, it's getting past the previous error.
Now I have a new error:
C:\GDBee-master\GDBee-master\src\table.py in <module>
3
4 from collections import OrderedDict
----> 5 import pandas as pd
6
7 from PyQt5.Qt import QApplication
ModuleNotFoundError: No module named 'pandas'
Part 3:
I don’t know why I’m getting that error, since pandas is already installed in Anaconda Navigator.
Just to see what happens, I installed a bunch of other pandas-related libraries in Anaconda Navigator.
- geopandas
- geopandas-base
- pandas-datareader
- pandasql
Screenshot.
I restarted Anaconda Navigator and tried to run GDBee again.
Now I get a different error:
C:\GDBee-master\GDBee-master\src\geodatabase.py in <module>
3
4 import osgeo.ogr
----> 5 ogr.UseExceptions()
6
7
NameError: name 'ogr' is not defined
Part 4:
In C:\GDBee-master\GDBee-master\src\geodatabase.py
, I changed import osgeo.ogr
to import osgeo.ogr as ogr
. So that osgeo.ogr
will be treated as ogr
.
Now I'm getting the pandas error again.
Part 5:
I updated pandas in Anaconda Navigator. Screenshot.
Previously, when I tried to update pandas, nothing happened. I'd hit Apply, and it would think for a few minutes, but ultimately, nothing changed.
But this time, updating pandas worked. Maybe it was because I installed those other pandas libraries too? Maybe they triggered pandas to get updated properly? I'm not sure.
Anyway, I updated pandas and restarted my computer.
Success:
Now, when I run GDBee, it loads the GDBee program in PyQT.
And when I browse to a file geodatabase and run a query on it, it works.
By the way, when it comes to file geodatabases, the WHERE clause in the screenshot works in GDBee, but it doesn't work as an SQL expression in ArcGIS Pro. See: Clarify the docs: Correlated subqueries not supported in FGDB SQL expressions.
So that's why I need GDBee: it has much better SQL support for file geodatabases than ArcGIS does.
Alternatively, it looks like there is a similar paid product here: https://sql4arc.com/ by Manifold (untested).