Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Watxtract-Christina opened this issue Mar 28, 2019 · 8 comments
Open

Comments

@Watxtract-Christina
Copy link

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
Copy link
Owner

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

from pip._internal import main as pip
pip(['install', '--user', 'scikit-learn'])

@Watxtract-Christina
Copy link
Author

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
Copy link
Owner

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
Copy link
Owner

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

@ppopoca
Copy link

ppopoca commented Sep 23, 2019

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
Copy link

vidlb commented Mar 3, 2020

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 qgis/QGIS#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
Copy link

vidlb commented Mar 4, 2020

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
Copy link
Owner

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 ?

n103 added a commit to n103/dzetsaka that referenced this issue Jun 16, 2020
Successfully tested with macOS 10.13.6 (High Sierra) and 10.15.5 (Catalina), QGIS 3.10.
Solution from this comment: nkarasiak#15 (comment).
Not sure if restart is actually required.
In macOS High Sierra, QGIS was not responidng during the classifiation but still succeeded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants