Opened 6 months ago

Closed 6 weeks ago

#649 closed defect (fixed)

Installing Fiona, Geopandas or rasterio using OSGeo4W breaks QGIS python

Reported by: cratcliff Owned by: osgeo4w-dev@…
Priority: critical Component: Package
Version: Keywords: fiona geopanda rasterio
Cc:

Description

I am installing fiona, geopandas and rasterio for python 3 using OSGeo4w on Windows 10 for use with QGIS 3.14.1 and above.

After installing each of these independently, the python console in QGIS breaks and I am getting the following message

Failed to open Python console:

Traceback (most recent call last):
  File "C:\PROGRA~1\QGIS3~1.14\apps\Python37\lib\site-packages\osgeo\osr.py", line 14, in swig_import_helper
    return importlib.import_module(mname)
  File "C:\PROGRA~1\QGIS3~1.14\apps\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 1006, in _gcd_import
  File "", line 983, in _find_and_load
  File "", line 967, in _find_and_load_unlocked
  File "", line 670, in _load_unlocked
  File "", line 583, in module_from_spec
  File "", line 1043, in create_module
  File "", line 219, in _call_with_frames_removed
ImportError: DLL load failed: The specified procedure could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\PROGRA~1\QGIS3~1.14\apps\Python37\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "", line 1, in 
  File "C:/PROGRA~1/QGIS3~1.14/apps/qgis/./python\qgis\utils.py", line 743, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "C:/PROGRA~1/QGIS3~1.14/apps/qgis/./python/plugins\processing\__init__.py", line 35, in 
    from processing.tools.raster import *  # NOQA
  File "C:/PROGRA~1/QGIS3~1.14/apps/qgis/./python\qgis\utils.py", line 743, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "C:/PROGRA~1/QGIS3~1.14/apps/qgis/./python/plugins\processing\tools\raster.py", line 26, in 
    from osgeo import gdal
  File "C:/PROGRA~1/QGIS3~1.14/apps/qgis/./python\qgis\utils.py", line 743, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "C:\PROGRA~1\QGIS3~1.14\apps\Python37\lib\site-packages\osgeo\gdal.py", line 1756, in 
    import osgeo.ogr
  File "C:/PROGRA~1/QGIS3~1.14/apps/qgis/./python\qgis\utils.py", line 743, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "C:\PROGRA~1\QGIS3~1.14\apps\Python37\lib\site-packages\osgeo\ogr.py", line 260, in 
    import osgeo.osr
  File "C:/PROGRA~1/QGIS3~1.14/apps/qgis/./python\qgis\utils.py", line 743, in _import
    mod = _builtin_import(name, globals, locals, fromlist, level)
  File "C:\PROGRA~1\QGIS3~1.14\apps\Python37\lib\site-packages\osgeo\osr.py", line 17, in 
    _osr = swig_import_helper()
  File "C:\PROGRA~1\QGIS3~1.14\apps\Python37\lib\site-packages\osgeo\osr.py", line 16, in swig_import_helper
    return importlib.import_module('_osr')
  File "C:\PROGRA~1\QGIS3~1.14\apps\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_osr'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 2, in 
  File "C:/PROGRA~1/QGIS3~1.14/apps/qgis/./python\console\console.py", line 47, in show_console
    _console = PythonConsole(parent)
  File "C:/PROGRA~1/QGIS3~1.14/apps/qgis/./python\console\console.py", line 83, in __init__
    self.console = PythonConsoleWidget(self)
  File "C:/PROGRA~1/QGIS3~1.14/apps/qgis/./python\console\console.py", line 113, in __init__
    self.shell = ShellScintilla(self)
  File "C:/PROGRA~1/QGIS3~1.14/apps/qgis/./python\console\console_sci.py", line 104, in __init__
    self.runsource(line)
  File "C:/PROGRA~1/QGIS3~1.14/apps/qgis/./python\console\console_sci.py", line 679, in runsource
    return super(ShellScintilla, self).runsource(source, filename, symbol)
  File "C:\PROGRA~1\QGIS3~1.14\apps\Python37\lib\code.py", line 74, in runsource
    self.runcode(code)
  File "C:\PROGRA~1\QGIS3~1.14\apps\Python37\lib\code.py", line 94, in runcode
    self.showtraceback()
  File "C:\PROGRA~1\QGIS3~1.14\apps\Python37\lib\code.py", line 148, in showtraceback
    sys.excepthook(ei[0], ei[1], last_tb)
  File "C:/PROGRA~1/QGIS3~1.14/apps/qgis/./python\console\console_sci.py", line 675, in excepthook
    self.write("".join(traceback.format_exception(etype, value, tb)))
  File "C:/PROGRA~1/QGIS3~1.14/apps/qgis/./python\console\console_sci.py", line 660, in write
    sys.stderr.write(txt)
AttributeError: 'NoneType' object has no attribute 'write'

How do I fix this to be able to use QGIS and these packages.

Change History (6)

comment:1 Changed 6 months ago by jef

Quick workaround: create an empty directory .libs in %OSGEO4W_ROOT%\apps\Python37\lib\site-packages\fiona and %OSGEO4W_ROOT%\apps\Python37\lib\site-packages\rasterio or change %OSGEO4W_ROOT%/apps/qgis/python/qgis/utils.py by adding and os.path.isdir(p):

diff --git a/python/utils.py b/python/utils.py
index c2a403efec..6be762ced9 100644
--- a/python/utils.py
+++ b/python/utils.py
@@ -780,7 +780,7 @@ def _import(name, globals={}, locals={}, fromlist=[], level=None):
                 global _RemoveDllDirectory

                 for p in set(new_path.split(';')) - set(old_path.split(';')):
-                    if p is not None and p not in _import_path:
+                    if p is not None and p not in _import_path and os.path.isdir(p):
                         _import_paths[p] = _AddDllDirectory(p)

                 for p in set(old_path.split(';')) - set(new_path.split(';')):

comment:2 Changed 6 months ago by jef

Resolution: fixed
Status: newclosed

python3-fiona / python3-rasterio updated to include empty .libs

comment:4 Changed 6 months ago by cratcliff

Thanks for looking into this.

The quick workaround of creating the .libs folder works for QGIS 3.16

Is there an equivalent method for earlier version ie QGIS 3.14? Adding the .libs folder doesn't work. I tried using using 3.14.1 and 3.14.16.

Last edited 6 months ago by cratcliff (previous) (diff)

comment:5 Changed 6 months ago by cratcliff

Resolution: fixed
Status: closedreopened

comment:6 Changed 6 weeks ago by jef

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.