0

While importing rasterio in QGIS is showing Exception: std::bad_alloc

Qgis Screenshot

When I re-import rasterio afterwards it shows error:

Traceback (most recent call last): File "/usr/lib/python3.8/code.py", line 63, in runsource code = self.compile(source, filename, symbol) File "/usr/lib/python3.8/codeop.py", line 178, in __call__ return _maybe_compile(self.compiler, source, filename, symbol) File "/usr/lib/python3.8/codeop.py", line 106, in _maybe_compile raise err1 File "/usr/lib/python3.8/codeop.py", line 93, in _maybe_compile code1 = compiler(source + "\n", filename, symbol) File "/usr/lib/python3.8/codeop.py", line 143, in __call__ codeob = compile(source, filename, symbol, self.flags, 1) File "<input>", line 1 import rasterio ^ SyntaxError: multiple statements found while compiling a single statement 

Python: 3.8.10
rasterio: 1.2.10
OS: Ubuntu 20.04 LTS . I installed QGIS by apt, and rasterio by pip.

6
  • i tried uninstalling rasterio and reinstalling, it does'nt helped. Commented Nov 22, 2021 at 8:47
  • How exactly did you install, using pip install rasterio or pip3 install rasterio or python3 -m pip install rasterio? Commented Nov 22, 2021 at 9:44
  • Initially i reinstalled by pip install rasterio but now i also tried sudo apt install python3-rasterio it also didn't worked. Commented Nov 23, 2021 at 8:17
  • @KadirŞahbaz any update? Commented Nov 24, 2021 at 11:09
  • Unfortunately no. Do you get the same error when using the python in terminal? Commented Nov 24, 2021 at 11:21

1 Answer 1

0

I had the same error and it didn't really come from rasterio but pyproj. Check this link:

https://pyproj4.github.io/pyproj/stable/gotchas.html#internal-proj-error-sqlite-error-on-select

In my case, qgis was installed with apt and so the pyproj package came from apt. But at the same time I had something like this in my code:

toto.py

from A.common.wms import WMS 

A/common/src/wms.py

import pyproj class WMS: pass 

"A.common" is a package that I have installed with pip in the user environment (somewhere in .local for linux). So it means that qgis tried to import pyproj from the user site package while it was probably imported previously. Even if it was not imported, I mixed different version of pyproj and it was not good.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.