Is there a way to tweak the fiona/gdal/osgeo packages installed through Anaconda so that they can be used to read/write GDB files using the ESRI FileGDB driver? The main thing I'm actually trying to achieve is writing to GDB a file.
I have found multiple answers online, but all of them involve re-installing OSGeo or GDAL from the python wheel files. These methods do not work for me because I installed fiona, OSGeo and GDAL using Anaconda. So none of the solutions I found online (listed below) seem to work. Furthermore, the approach of overwriting conda's whole installation of GDAL using pip install
also does not work.
I have already downloaded the DLL file from ESRI, placed it in my C:\...\Lib\site-packages\osgeo
folder and added a new environment variable called GDAL_DRIVER_PATH
indicating the appropriate path. However, contrary to the suggestions in the posts listed below, the __init__.py
inside the osgeo
folder does not have a commented line that reads os.environ['GDAL_DRIVER_PATH'] = os.path.join(os.path.dirname(__file__), 'gdalplugins')
. Therefore, I am not sure where to include this line in my own file system.
Similar (unresolved) discussions can be found on the GeoPandas and on the Fiona Github pages.
Also, here is a list of related posts/questions/sites with relevant info but which ultimately did not solve my problem.
- How to add support for FileGDB (Esri file gdb API) driver in fiona?
- How to edit file geodatabase in Python using FileGDB Driver?
- Geopandas: Write layer back into GeoDataBase
- Exporting PostGIS Data
- Setting up GDAL/OGR with FileGDB Driver for Python on Windows
- GDAL FileGDB Driver with Anaconda / ArcGIS Pro (Unanswered)
- GDAL Documentation on using ESRI File Geodatabase (FileGDB)
- How to access feature classes in file geodatabases with Python and GDAL?
- ESRI FileGDB API on GitHub
How I installed Fiona and other packages:
I'm currently using Windows 10. After installing Anaconda, I created a new environment called myenv
and installed the main libraries I was going to use:
conda create -n myenv pandas geopandas fiona spyder numpy scipy
GDAL was automatically installed as one of the associated/required packages for fiona and geopandas.
In my command prompt, when I activate myenv
and type gdalinfo --version
, I get the following response:
GDAL 3.0.2, released 2019/10/28
When I use the python-based route, I get the same answer.
import osgeo.gdal
print(osgeo.gdal.__version__)
>3.0.2
Overwriting conda's installation of GDAL using pip install GDALxyz.whl
I downloaded the GDAL wheels from the gohlke
repository and ran pip install "GDAL-3.3.3-cp38-cp38-win_amd64.whl"
, added Estri's FileGDB driver DLLs into the appropriate folders, added the appropriate environment variables and it still didn't work.
Additional Notes:
If the answer involves something like "you need to compile/build GDAL from source files", please include a step-by-step on how to do so, including what to do after "building" (for example, where to put the files and how to get Python to use the newly-built version of GDAL within a specific conda environment). I know this is a lot to ask, and I apologize for doing so. It's just that I have tried looking into this process and it is not very newbie-friendly.
PATH
) and 2. the GDAL FileGDB driver (either compiled into the GDAL library itself or compiled separately as a driver plugin and stored in theGDAL_DRIVER_PATH
). You only have 1. (the API library) and I don't think Anaconda or conda-forge provide a filegdb enabled GDAL or a driver plugin so you're out of luck there. You may be able to get it to work if you can find and download a version of the driver as a plugin compiled for the same version of gdal that your conda env provides