QGIS cannot import SciPy (QGIS 3.6, Ubuntu 18.04)

Issue #284 closed
Javier Navarro created an issue

Hi everyone,

I’ve submitted this question too to GIS StackExchange. I had been struggling to get QGIS installed because (currently) the ubuntugis repo seems to not be working well (couldn’t load Python at all). I got around that problem by installing QGIS using flatpak.

I neeed to use the ENMAPBox plugin, which requires SciPy, Numpy, and Sklearn modules. Ubuntu came with Python 3.6.8 installed and QGIS brought with it Python 3.7.3. ENMAPBox cannot start because it can’t find either of those modules, and importing them from the console yields the same response. I followed the plugin’s instructions to install those packages using python3 -m pip install.

I’ve verified that the executable used by QGIS python console is /usr/bin/python3, and inspecting sys.path shows that /usr/lib/python3/dis-packages is not in the path (so it would make sense that it can’t find the packages I installed using pip3).

Sys.path looks like this:

['/app/share/qgis/python', '/home/nav00a/.var/app/org.qgis.qgis/data/QGIS/QGIS3/profiles/default/python', '/home/nav00a/.var/app/org.qgis.qgis/data/QGIS/QGIS3/profiles/default/python/plugins', '/app/share/qgis/python/plugins', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/usr/lib/python3.7/site-packages', '/app/lib/python3.7/site-packages', '/app/lib/python3.7/site-packages/numpy-1.14.3-py3.7-linux-x86_64.egg', '/app/lib/python3.7/site-packages/MarkupSafe-1.0-py3.7-linux-x86_64.egg', '/home/nav00a/.var/app/org.qgis.qgis/data/QGIS/QGIS3/profiles/default/python', '/home/nav00a/.var/app/org.qgis.qgis/data/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/site-packages', '/home/nav00a/.var/app/org.qgis.qgis/data/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/enmapbox', '/usr/lib/python3/dist-packages']

Note the last item is there because I appended it, it’s not there by default.

To get QGIS to import SciPy I’ve tried a number of things:

Appending /usr/lib/python3/dist-packages to sys.path

Redirecting pip3 to /usr/lib/python3.7/site-packages

Adding .pth files to /usr/lib/python3.7/site-packages and /home/nav00a/.var/app/org.qgis.qgis/data/QGIS/QGIS3/profiles/default/python/plugins/enmapboxplugin/site-packages with links to /usr/lib/python3/dust-packages and /usr/lib/python3.7/site-packages

Unfortunately the behaviour remains the same. If I import SciPy this is what I get:

Traceback (most recent call last):

File "/usr/lib/python3.7/code.py", line 90, in runcode

exec(code, self.locals)

File "<input>", line 1, in <module>

File "/app/share/qgis/python/qgis/utils.py", line 672, in _import

mod = _builtin_import(name, globals, locals, fromlist, level)

ModuleNotFoundError: No module named 'scipy'

A user on GIS StackExchange managed to get EnMapBox installed in two minutes using Debian 10 Buster. Changing distros may or may not be an option for me, depends on what my IT department allows me to do.

Any pointers towards a solution will be greatly appreciated 🙂

Cheers

Javi

Edit: Just found out the flatpak version of QGIS does not allow for other python modules to be installed, so I’m going back to trying to install QGIS via the normal repository (which is still broken).

Edit2: It is known that (as of 02/09/2019) the ubuntugis repo is broken so installing from there will result in broken dependencies that will not be installed. I was having the exact same issues installing from the Ubuntu LTR release but the nightly release seems to be working just fine.

Comments (10)

  1. Benjamin Jakimow

    I wonder that SciPy is not already part of the QGIS installation.

    @Fabian Thiel to your experience, what is the easiest way to install SciPy and ScikitLearn?

  2. Javier Navarro reporter

    In my case installing the nightly-release fixed the issues of QGIS not recognising new modules installed via pip3. The issue was that flatpak creates an immutable version of QGIS (so no new modules allowed). After installing the nightly releases of 3.4 and then 3.8 pip3 worked fine.

    Get Outlook for iOShttps://aka.ms/o0ukef

  3. Javier Navarro reporter

    Hi Fabian, it didn’t because EnMap-Box requires a QGIS that’s compiled against Qt 5.10 or higher an in Ubuntu 18.04 qt5-default is 5.9.5. I use an enterprise VM and I can’t upgrade Ubuntu so I gave up (for now) and installed it in Windows.

  4. Benjamin Jakimow

    @Javier Navarro Cámara have you tested to install the missing packages into your user space (```pip install --user <package>```)? This should work even without having writing access to the python distribution itself.

    python -m pip install --user scipy 
    

  5. Javier Navarro reporter

    Sorry, I think I didn’t explain myself well. The solution did work in the sense that I was able to install SciPy and sklearn and get EnMapBox installed. However the issue then was with EnMapBox GUI not starting because of at Qt issue (which you helped me understand in a separate ticket).

  6. Log in to comment