danioxoli / HotSpotAnalysis_Plugin

A QGIS plugin for hotspot analysis
GNU General Public License v3.0
55 stars 12 forks source link

ModuleNotFoundError: No module named 'pysal.esda #23

Closed bpmcrae closed 5 years ago

bpmcrae commented 5 years ago

I am running QGIS 3.4.4 in a Windows environment.

I appear to have successfully installed pysal. Running "import pysal" in the QGIS Python console does not generate any errors.

However, when I try to activate the HotSpot Analysis plugin, I get an error message (see below). I did find some discussion of this on StackFlow (Anita's response I think) and tried some of the suggestions there, but no success As there didn't seem to be an issue with 'pysal.esda' in the title, I thought I'd post one. Apologies if there is already a related post that I missed.

Couldn't load plugin 'HotSpotAnalysis_Plugin-qgis3' due to an error when calling its classFactory() method

ModuleNotFoundError: No module named 'pysal.esda' Traceback (most recent call last): File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 335, in startPlugin plugins[packageName] = package.classFactory(iface) File "C:/Users/Brian/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\HotSpotAnalysis_Plugin-qgis3__init__.py", line 34, in classFactory from .hotspot_analysis import HotspotAnalysis File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 672, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "C:/Users/Brian/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\HotSpotAnalysis_Plugin-qgis3\hotspot_analysis.py", line 39, in from pysal.esda.getisord import * File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 672, in _import mod = _builtin_import(name, globals, locals, fromlist, level) ModuleNotFoundError: No module named 'pysal.esda'

Python version: 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] QGIS version: 3.4.4-Madeira Madeira, 73c31df831

Python Path: C:/OSGEO4~1/apps/qgis/./python C:/Users/Brian/AppData/Roaming/QGIS/QGIS3\profiles\default/python C:/Users/Brian/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins C:/OSGEO4~1/apps/qgis/./python/plugins C:\OSGeo4W64\bin\python37.zip C:\OSGEO4~1\apps\Python37\DLLs C:\OSGEO4~1\apps\Python37\lib C:\OSGeo4W64\bin C:\OSGEO4~1\apps\Python37 C:\OSGEO4~1\apps\Python37\lib\site-packages C:\OSGEO4~1\apps\Python37\lib\site-packages\win32 C:\OSGEO4~1\apps\Python37\lib\site-packages\win32\lib C:\OSGEO4~1\apps\Python37\lib\site-packages\Pythonwin C:/Users/Brian/AppData/Roaming/QGIS/QGIS3\profiles\default/python C:\Users\Brian\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins C:/Users/Brian/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\qgis_resource_sharing C:\Users\Brian\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\qgis_resource_sharing C:\Users\Brian\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\qgis_resource_sharing\ext_libs

danioxoli commented 5 years ago

Dear Brian,

Could you please check which version of pysal are you using? Do: py3_env pip show pysal

This should not happen normally with version 1.14 (I made my test on Windows and QGIS3 using version 1.14.3).

I know that on the dev version 2.0, some import API has changed therefore I will modify the import pattern once this will be the stable version.

Let me know thus I would be able to better look inside the issue.

Best, Daniele

bpmcrae commented 5 years ago

Hi Daniele,

Thanks for the prompt reply. I appear to be running the dev version (see below).

C:>py3_env

C:>SET PYTHONPATH=

C:>SET PYTHONHOME=C:\OSGEO4~1\apps\Python37

C:>PATH C:\OSGEO4~1\apps\Python37;C:\OSGEO4~1\apps\Python37\Scripts;{app};C:\OSGEO4~1\apps\Python27\Scripts;C:\OSGEO4~1\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBem;C:\Program Files\R\R-3.5.1\bin\x64

C:>pip show pysal Name: pysal Version: 2.0.0 Summary: A library of spatial analysis functions. Home-page: http://pysal.org Author: None Author-email: None License: BSD Location: c:\osgeo4~1\apps\python37\lib\site-packages Requires: scipy, pandas, seaborn, matplotlib, descartes, palettable Required-by:

C:>

I uninstalled pysal and then installed 1.14, using the code below based on http://pysal.org/about.html#migrating-to-pysal-2-0!

C:>python -m pip uninstall pysal Uninstalling pysal-2.0.0: Would remove: c:\osgeo4~1\apps\python37\lib\site-packages\pysal-2.0.0-py3.7.egg-info c:\osgeo4~1\apps\python37\lib\site-packages\pysal* Proceed (y/n)? y Successfully uninstalled pysal-2.0.0

C:>python -m pip install pysal==1.14.4.post2 Collecting pysal==1.14.4.post2 Using cached https://files.pythonhosted.org/packages/e6/e4/c4fb97674458dee71ce8dda517f6ad02c498518d26a0c4b8b692d741c3b9/PySAL-1.14.4.post2.tar.gz Requirement already satisfied: scipy>=0.11 in c:\osgeo4~1\apps\python37\lib\site-packages (from pysal==1.14.4.post2) (1.1.0) Requirement already satisfied: numpy>=1.3 in c:\osgeo4~1\apps\python37\lib\site-packages (from pysal==1.14.4.post2) (1.15.4) Installing collected packages: pysal Running setup.py install for pysal ... done Successfully installed pysal-1.14.4.post2

C:>

This appeared to work -- I didn't get an error when I activated the plugin in QGIS. However, when I clicked on the plugin icon on the toolbar I got an error (sorry, didn't copy this log).

I shut-down and then restarted QGIS and got a message that it couldn't load the HotSpot Analysis plug-in:

2019-02-01T08:48:39 WARNING Python error : Couldn't load plugin 'HotSpotAnalysis_Plugin-qgis3' due to an error when calling its classFactory() method See message log (Python Error) for more details.

2019-02-01T08:48:39 WARNING Traceback (most recent call last): File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 335, in startPlugin plugins[packageName] = package.classFactory(iface) File "C:/Users/Brian/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\HotSpotAnalysis_Plugin-qgis3__init.py", line 34, in classFactory from .hotspot_analysis import HotspotAnalysis File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 672, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "C:/Users/Brian/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\HotSpotAnalysis_Plugin-qgis3\hotspot_analysis.py", line 38, in import pysal File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 672, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "C:\OSGEO4~1\apps\Python37\lib\site-packages\pysal__init__.py", line 107, in import pysal.spreg File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 672, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "C:\OSGEO4~1\apps\Python37\lib\site-packages\pysal\spreg\init.py", line 1, in from .ols import * File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 672, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "C:\OSGEO4~1\apps\Python37\lib\site-packages\pysal\spreg\ols.py", line 7, in from . import user_output as USER File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 672, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "C:\OSGEO4~1\apps\Python37\lib\site-packages\pysal\spreg\user_output.py", line 9, in from . import diagnostics File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 672, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "C:\OSGEO4~1\apps\Python37\lib\site-packages\pysal\spreg\diagnostics.py", line 12, in from .utils import spmultiply, sphstack, spmin, spmax File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 672, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "C:\OSGEO4~1\apps\Python37\lib\site-packages\pysal\spreg\utils.py", line 10 author__ = "Luc Anselin luc.anselin@asu.edu, \ ^ SyntaxError: EOL while scanning string literal

I then tried turning the plugin off and then on and this time I got an error:

Couldn't load plugin 'HotSpotAnalysis_Plugin-qgis3' due to an error when calling its classFactory() method

AttributeError: module 'pysal' has no attribute 'common' Traceback (most recent call last): File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 335, in startPlugin plugins[packageName] = package.classFactory(iface) File "C:/Users/Brian/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\HotSpotAnalysis_Plugin-qgis3__init__.py", line 34, in classFactory from .hotspot_analysis import HotspotAnalysis File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 672, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "C:/Users/Brian/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\HotSpotAnalysis_Plugin-qgis3\hotspot_analysis.py", line 38, in import pysal File "C:/OSGEO4~1/apps/qgis/./python\qgis\utils.py", line 672, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "C:\OSGEO4~1\apps\Python37\lib\site-packages\pysal__init__.py", line 46, in pysal.common.pandas = pandas AttributeError: module 'pysal' has no attribute 'common'

Python version: 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] QGIS version: 3.4.4-Madeira Madeira, 73c31df831

Python Path: C:/OSGEO4~1/apps/qgis/./python C:/Users/Brian/AppData/Roaming/QGIS/QGIS3\profiles\default/python C:/Users/Brian/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins C:/OSGEO4~1/apps/qgis/./python/plugins C:\OSGeo4W64\bin\python37.zip C:\OSGEO4~1\apps\Python37\DLLs C:\OSGEO4~1\apps\Python37\lib C:\OSGeo4W64\bin C:\OSGEO4~1\apps\Python37 C:\OSGEO4~1\apps\Python37\lib\site-packages C:\OSGEO4~1\apps\Python37\lib\site-packages\win32 C:\OSGEO4~1\apps\Python37\lib\site-packages\win32\lib C:\OSGEO4~1\apps\Python37\lib\site-packages\Pythonwin C:/Users/Brian/AppData/Roaming/QGIS/QGIS3\profiles\default/python C:\Users\Brian\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins C:/Users/Brian/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\qgis_resource_sharing C:\Users\Brian\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\qgis_resource_sharing C:\Users\Brian\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\qgis_resource_sharing\extlibs

Any suggestions appreciated...

danioxoli commented 5 years ago

Please try this work workaround that I suggested on issue #15

“I found a workaround that allowed me to run the plugin on QGIS 3.4 on Windows.

After installing PySAL following the instructions, open this file in a text editor as Admin:

"C:\Program Files\QGIS 3.4\apps\Python37\Lib\site-packages\pysal\ init .py"

comment line 95, like:

# import pysal.spreg

((I also trashed the subfolder: "C:\Program Files\QGIS 3.4\apps\Python37\Lib\site-packages\pysal\spreg“ to be sure it won’t be called. I think this is not necessary)

Save the changes and run QGIS. The problem should be solved!”

Let me know if this is helpful!

I still have not found the time for a full test on Py3.7 and QGIS3.4. I whish to start to modify the code soon to take into account the upcoming changes in the pysal import API, sorry for that.

Daniele

bpmcrae commented 5 years ago

Hi Danielle,

Thanks again for the assistance. After the suggested edits, plugin loads, but I get the following error when trying to run it:

2019-02-04T08:29:23 WARNING Traceback (most recent call last): File "C:/Users/Brian/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\HotspotAnalysis\hotspot_analysis.py", line 546, in run layers, layers_shp = self.loadLayerList() TypeError: cannot unpack non-iterable NoneType object

danioxoli commented 5 years ago

Hi,

This is actually due to a bug (or better to a missing functionality) of the plugin. Just move in the upper position of your layers panel the shapefile you want to analyse. The error appears when in the first position of the layers panel is present a something different than a shapefile.

Let me know if I got the point!

Daniele

bpmcrae commented 5 years ago

Hi Daniele,

You were close to correct and the info you provided allowed me to identify the issue. It was actually that I didn't have any shapefiles as I was using geopackages. Once I exported to a shapefile it worked.

Thanks, Brian

KumawatP commented 4 years ago

I am also having the same error as while installing the plugin in qgis, I already installed pysal in python qgis console and in python environment:-

Couldn't load plugin 'HotSpotAnalysis_Plugin-qgis3' due to an error when calling its classFactory() method

ModuleNotFoundError: No module named 'pysal.esda' Traceback (most recent call last): File "/Applications/QGIS3.12.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 334, in _startPlugin plugins[packageName] = package.classFactory(iface) File "/Users/pinky/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/HotSpotAnalysis_Plugin-qgis3/init.py", line 34, in classFactory from .hotspot_analysis import HotspotAnalysis File "/Applications/QGIS3.12.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 744, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "/Users/pinky/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/HotSpotAnalysis_Plugin-qgis3/hotspot_analysis.py", line 39, in from pysal.esda.getisord import * File "/Applications/QGIS3.12.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 744, in _import mod = _builtin_import(name, globals, locals, fromlist, level) ModuleNotFoundError: No module named 'pysal.esda'

Python version: 3.7.3 (default, Mar 27 2019, 09:23:15) [Clang 10.0.1 (clang-1001.0.46.3)] QGIS version: 3.12.1-București București, 121cc00ff0

Python Path: /Users/pinky/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/AequilibraE/aequilibrae /Users/pinky/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/AequilibraE/aequilibrae /Applications/QGIS3.12.app/Contents/MacOS/../Resources/python /Users/pinky/Library/Application Support/QGIS/QGIS3/profiles/default/python /Users/pinky/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins /Applications/QGIS3.12.app/Contents/MacOS/../Resources/python/plugins /Applications/QGIS3.12.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python37.zip /Applications/QGIS3.12.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.7/lib-dynload /Applications/QGIS3.12.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.7/site-packages/geos /Applications/QGIS3.12.app/Contents/Resources/python /Applications/QGIS3.12.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.7 /Applications/QGIS3.12.app/Contents/Frameworks/Python.framework/Versions/Current/lib/python3.7/site-packages /Users/pinky/Library/Application Support/QGIS/QGIS3/profiles/default/python /Users/pinky/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/HCMGIS/forms /Users/pinky/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/mmqgis/forms . /Users/pinky/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/HCMGIS/forms

Please help me to solve this problem on mac to install this plugin in Qgis. Thanks

danioxoli commented 4 years ago

your problem is in the version of PySAL which must be the 1.14 if using the Plugin version published on the official QGIS plugin repository.

Actually, QGIS 3.10 on macOS comes with PySAL 2.0 already installed and luckily there is no need to install any dependency. However, the installation must be done using the zip file of this branch: https://github.com/danioxoli/HotSpotAnalysis_Plugin/tree/qgis3pysal2 (after removing your current plugin version)

Please, check the short documentation at the above link and let me know if the trick works also on QGIS 3.12.

Best,

vovchykbratyk commented 4 years ago

I gav

your problem is in the version of PySAL which must be the 1.14 if using the Plugin version published on the official QGIS plugin repository.

Actually, QGIS 3.10 on macOS comes with PySAL 2.0 already installed and luckily there is no need to install any dependency. However, the installation must be done using the zip file of this branch: https://github.com/danioxoli/HotSpotAnalysis_Plugin/tree/qgis3pysal2 (after removing your current plugin version)

Please, check the short documentation at the above link and let me know if the trick works also on QGIS 3.12.

Best,

I gave this a shot because I was running into the same problem. In this case it's trying to invoke pysal.explore.esda and failing.

It seems like there are a lot of breaks between pysal versions :(

danioxoli commented 4 years ago

Yes,

PySAL API had a huge API change between versions 1.14 (previous LTR) and 2.0. The main issue is to understand which one your local QGIS env is using (especially on macOS). On issue #49 there is a nice explanation to configure PySAL 1.14 for QGIS 3.10 on macOS. I hope this will help.

Best,

Daniele

vovchykbratyk commented 4 years ago

Thanks @danioxoli I am on Windows 10, QGIS 3.12. Between this and the readme (which I had neglected to read all the way through) it's working! My issue is that I simply did python -m pip install pysal, which brought in 2.2.0. I downgraded to 2.0.0 it installed without error.

KatjaKalkschmied commented 1 year ago

@danioxoli : I have run through all the steps to install the hotspot analysis. I think I got quite a lot right, but the plugin simply won't run due to the error ModuleNotFoundError: No module named 'pysal.explore'.

I have the psyal Version: 1.14.3 installed. did the # import pysal.spreg in the init .py file. I even cancelled out the pandas part following hte youtube video "Calculating Statistically Significant Hotspots Using the Hotspot Analysis Plugin in QGIS". Yet, it does not want to run.

What is the problem with this pysal.explore? I would be very thankful for support.

Regards, Katja

Here the error message:

Couldn't load plugin 'HotspotAnalysis' due to an error when calling its classFactory() method

ModuleNotFoundError: No module named 'pysal.explore' Traceback (most recent call last): File "C:\PROGRA~1/QGIS32~1.3/apps/qgis/./python\qgis\utils.py", line 423, in _startPlugin plugins[packageName] = package.classFactory(iface) File "C:\Users/katja/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\HotspotAnalysis__init__.py", line 34, in classFactory from .hotspot_analysis import HotspotAnalysis File "C:\PROGRA~1/QGIS32~1.3/apps/qgis/./python\qgis\utils.py", line 888, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "C:\Users/katja/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\HotspotAnalysis\hotspot_analysis.py", line 39, in from pysal.explore.esda.getisord import * File "C:\PROGRA~1/QGIS32~1.3/apps/qgis/./python\qgis\utils.py", line 888, in _import mod = _builtin_import(name, globals, locals, fromlist, level) ModuleNotFoundError: No module named 'pysal.explore'

Python version: 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] QGIS version: 3.22.3-Białowieża Białowieża, 1628765ec7