nkarasiak / dzetsaka

dzetsaka : classification plugin for Qgis
GNU General Public License v3.0
80 stars 20 forks source link

Failed to recognize scikit-learn in qgis 3.6 for ubuntu #15

Open Watxtract-Christina opened 5 years ago

Watxtract-Christina commented 5 years ago

When I tried to run SVM in qgis using the plugin, I got the library missing message "Scikit-learn library is missing on your computer." Although I have scikit-learn in my system: Requirement already satisfied: scikit-learn in ./.local/lib/python3.6/site-packages (0.20.3) Requirement already satisfied: scipy>=0.13.3 in ./.local/lib/python3.6/site-packages (from scikit-learn) (1.2.1) Requirement already satisfied: numpy>=1.8.2 in ./.local/lib/python3.6/site-packages (from scikit-learn) (1.16.2) How to let QGIS recognize the library? System: ubuntu 18.04. Try type:import sklearn in python console in qgis, it seems the scikit-learn is not installed in qgis.

nkarasiak commented 5 years ago

Helllo, Could you try this in the Qgis python console :

from pip._internal import main as pip
pip(['install', '--user', 'scikit-learn'])
Watxtract-Christina commented 5 years ago

Traceback (most recent call last): File "/usr/lib/python3.6/code.py", line 91, in runcode exec(code, self.locals) File "", line 1, in File "/usr/lib/python3/dist-packages/qgis/utils.py", line 672, in _import mod = _builtin_import(name, globals, locals, fromlist, level) ModuleNotFoundError: No module named 'pip._internal'

nkarasiak commented 5 years ago

Hello,

How did you install Qgis in ubuntu ? Because normally dependences installed in Ubuntu (pip/sklearn in python...) are shared inside Qgis environment. I'm not an expert of this, but try to install pip in the Qgis environment (I see differences between /usr/lib/python3/ used for Qgis in your installation and ./.local/lib/python3.6/ your default python path).

nkarasiak commented 5 years ago

@Watxtract-Christina , do you find a way to install scikit-learn since ?

ppopoca commented 5 years ago

I installed scikit-learn for QGIS 3.4 using pip3 instead of pip, because I have both python 2 and 3, and since QGIS 3+ versions are based on python 3, I guess this should work for you.

Also, thinking of lennepkade's comment, I have these paths:

scikit-learn in /usr/local/lib/python3.6/dist-packages scipy>=0.17.0 in /usr/lib/python3/dist-packages (from scikit-learn) numpy>=1.11.0 in /usr/lib/python3/dist-packages (from scikit-learn) joblib>=0.11 in /usr/local/lib/python3.6/dist-packages (from scikit-learn)

vidlb commented 4 years ago

Hello,

I found that the problem isn't due to sklearn install, but it is much more deep...or should I say recursive. "RecursionError: maximum recursion depth exceeded while calling a Python object".

I was able to catch it by adding a 'raise' in the dzetsaka.py file. It seems impossible to import sklearn from a pyqgis scope ; here is the traceback. traceback_sklearn.txt QGIS-3.10 ; python-3.7.3 ; scikit-learn-0.20.2

It looks pretty similar to an issue I opened on the QGIS repo (see https://github.com/qgis/QGIS/issues/33612 ) : there is no way to import pandas after qgis.core. Something related to special methods and attributes (__dict__)... it may be hard to fix for now.

vidlb commented 4 years ago

I was able to fix it with a newer version of sklearn. In Debian10 or Ubuntu18, the default version installed with apt is 0.20.x . I had to remove the system version and then install a 0.22 with pip, now everything seems to work ! May be you should add a requirements.txt or something like that to specify a minimum version.

nkarasiak commented 4 years ago

Hello @vidlb ,

Thanks for the feedback and for the solution !

@Watxtract-Christina and @ppopoca , if you still have scikit-learn issues (sklearn not found), can you type this in the OSGEO : python3 -m pip install scikit-learn -U --user

The -U forces the update of scikit-learn, as @vidlb found that maybe the problem came from version 0.20.*.

In any case, can you tell me if you found a successful solution ? Or if you still failed to use sklearn ?