Repository: geopandas/geopandas

Issue:
BUG: InvalidVersion error when writing a file on disk with engine=fiona
- [x] I have checked that this issue has not already been reported.
- [x] I have confirmed this bug exists on the latest version of geopandas.

Issue alrerady reported in [esri forum](https://community.esri.com/t5/arcgis-pro-questions/arcgispro-py39-gdal-version-3-7-0e-is-recognized/m-p/1364021) and [stack overflow](https://stackoverflow.com/questions/75994612/invalidversion-error-returned-when-writting-an-esri-shp-file-geopandas-geodata).

---



#### Code Sample, a copy-pastable example

```python
import geopandas as gpd
from shapely.geometry import Point

p = Point(0, 1)
gdf = gpd.GeoDataFrame(geometry=[p], crs=4326)
gdf.to_file("path/to/file.shp")
```

or

```python
from packaging.version import Version, InvalidVersion
import fiona
from fiona import Env as fiona_env
with fiona_env():
    gdal_version = fiona.env.get_gdal_release_name()
    Version(gdal_version)
```

#### Problem description

Impossible to write a vector on disk with `fiona`'s engine.
![297467541-64b4f5ee-c0e9-4fc2-8d04-9ea856659cc6](https://github.com/geopandas/geopandas/assets/67311115/6680b4c9-d16d-4086-b17a-bec371e76a07)

1. When writing a file on disk, `geopandas` checks `GDAL` versions through `fiona` using the `Version` package
2. `fiona` outputs a `GDAL` version not handled by `Version` (`3.7.0e` instead of `3.7.0`)
3. `geopandas` doesn't handle such exception (`InvalidVersion`) and fails


#### Expected Output

Handle the `InvalidVersion` error in this part of the code.

#### Output of ``geopandas.show_versions()``

<details>

```
import geopandas
geopandas.show_versions()
SYSTEM INFO
-----------
python     : 3.9.18 [MSC v.1931 64 bit (AMD64)]
executable : C:\Users\rbraun\Anaconda3\envs\arcgispro-eo\python.exe
machine    : Windows-10-10.0.19045-SP0
GEOS, GDAL, PROJ INFO
---------------------
GEOS       : 3.11.2
GEOS lib   : None
GDAL       : 3.7.0e
GDAL data dir: None
PROJ       : 9.2.0
PROJ data dir: C:\Users\rbraun\Anaconda3\envs\arcgispro-eo\Library\share\proj
PYTHON DEPENDENCIES
-------------------
geopandas  : 0.14.2
numpy      : 1.22.4
pandas     : 2.0.2
pyproj     : 3.6.0
shapely    : 2.0.1
fiona      : 1.8.21
geoalchemy2: None
geopy      : 2.4.1
matplotlib : 3.6.3
mapclassify: 2.5.0
pygeos     : None
pyogrio    : 0.6.0
psycopg2   : None
pyarrow    : 14.0.2
rtree      : 1.1.0
```

</details>

#### Workaround

The workaround is to write the file on disk using pyogrio as stated [here](https://geopandas.org/en/stable/docs/user_guide/io.html#reading-spatial-data):

```python
geopandas.options.io_engine = "pyogrio"
```


Discussion:
How did you install GDAL that it comes with such a version?
Unfortunately, it's the one coming with the ersi conda channel 🙄 
I know this is on their garden, but if you could just handle the `InvalidVersion` error, this would be a big help 🙏 

PS : I'm not the one having this bug, see the two linked issues in the header
I suppose we could strip the version of the appended e. Though this is clearly an issue caused by Esri that should be solved by Esri. They take perfectly fine software, apparently adapt it in some way and produce invalid version tag the original software never had and never would've because the versioning system is not a random collection of numbers and letters as Esri assumes... 
I know, I know, them having their own conda channel is a pain 😞
Unfortunatelly, I have no choice but using this software, and apparently this issues comes regularly.

They seems to be notified with the issue on their forum.

With `geopandas` 1.0.0 this may be automatically solved as the error doesn't happen with `pyogrio`.
> With geopandas 1.0.0 this may be automatically solved as the error doesn't happen with pyogrio.

For most of users yes, but Fiona will still be available and that code path shall work as well.

Resolving patch:
diff --git a/geopandas/io/file.py b/geopandas/io/file.py
--- a/geopandas/io/file.py
+++ b/geopandas/io/file.py
@@ -635,10 +635,12 @@ def _to_file_fiona(df, filename, driver, schema, crs, mode, **kwargs):
     with fiona_env():
         crs_wkt = None
         try:
-            gdal_version = fiona.env.get_gdal_release_name()
-        except AttributeError:
-            gdal_version = "2.0.0"  # just assume it is not the latest
-        if Version(gdal_version) >= Version("3.0.0") and crs:
+            gdal_version = Version(
+                fiona.env.get_gdal_release_name().strip("e")
+            )  # GH3147
+        except (AttributeError, ValueError):
+            gdal_version = Version("2.0.0")  # just assume it is not the latest
+        if gdal_version >= Version("3.0.0") and crs:
             crs_wkt = crs.to_wkt()
         elif crs:
             crs_wkt = crs.to_wkt("WKT1_GDAL")


Test patch: