3

I'm somewhat new to python and QGIS plugin development. I've created a plugin structure for QGIS using the Plugin Builder on QGIS and I've added some controls to the gui and managed to update the appropriate module binding to the gui.

I'm also trying to use sklearn library nearest neighbor in my plugin application. Everything works well until sklearn first runs and I get an error message as follows:

An error has occured while executing Python code:

Traceback (most recent call last): File "C:/Users/c_aaalam/.qgis2/python/plugins\FemtoCoverage\femto_coverage.py", line 282, in run distances, indices = nbrs.kneighbors(subs) File "C:/Users/c_aaalam/.qgis2/python/plugins\FemtoCoverage\sklearn\neighbors\base.py", line 332, in kneighbors return_distance=return_distance) File "binary_tree.pxi", line 1295, in sklearn.neighbors.kd_tree.BinaryTree.query (sklearn\neighbors\kd_tree.c:10386) File "C:/Users/c_aaalam/.qgis2/python/plugins\FemtoCoverage\sklearn\utils\validation.py", line 117, in array2d if sp.issparse(X): AttributeError: 'NoneType' object has no attribute 'issparse'

This is the script I'm running in my plugin:

nbrs = NearestNeighbors(n_neighbors = 1, algorithm='auto').fit(array1)
distances, indices = nbrs.kneighbors(array2)

It looks like the scipy sparse variable is "NoneType" and therefore the "issparse()" function is not recognized. I have placed the sklearn folder in the plugin directory (windows user) and added the necessary import sklearn to my plugin module.

Does anyone have experience working with sklearn in PyQt applications or specifically with developing QGIS plugins and can help me resolve this error?

Maybe I'm loading sklearn incorrectly?

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Feb 11, 2015 at 6:32
1
  • Sorry...also to add that this script and all the associated arrays work fine if I process this directly in the QGIS python console. The sklearn part is just not working in my plugin module execution. Commented Feb 11, 2015 at 6:40

1 Answer 1

1

I figured out the issue. The problem was I had sklearn in the same directory as my plugin files and not in the site-packages under my qgis installation.

Not 100% sure that was the issue but once I deleted sklearn from the plugin directory and installed it in site-packages, the issue was resolved. No more errors!

answered Feb 13, 2015 at 18:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.