danioxoli / HotSpotAnalysis_Plugin

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

HotSpot Analysis_Plugin with MacOS and QGIS 3.16 #61

Open dbrosi opened 3 years ago

dbrosi commented 3 years ago

Hi Everyone!

I am a very beginner coder and I am trying to install the HotSpot Analysis Plugin. I seem to be having some trouble beyond installing the correct pysal version and think it might be based on the pathname where QGIS is trying to call the python/pysal package. I went through all the steps posted on how to get the 1.4.3 version of pysal, but still with the same warning message from QGIS. Here is what my terminal says when I check what version of pysal I have:

Name: PySAL Version: 1.14.3 Summary: A library of spatial analysis functions. Home-page: http://pysal.org Author: None Author-email: None License: BSD Location: /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages Requires: scipy, numpy Required-by:

I even tried uploading the pysal file to the folder path that QGIS uses, but then just started hitting roadblocks of it not encountering other "modules" in that folder.

I am wondering if someone can help me figure out how to get QGIS to read the right pysal location for macOS? In terminal it says that the pysal package is located under /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages and my QGIS is mapping to /Applications/QGIS.app/Contents/Resources/python. I looked at other forums where they talk about code to change the PYTHONPATH - but none of them worked and I always ended up with error messages in either terminal or QGIS console.

Just for reference here is the error message I get and why I think that it is a problem with the pathname.

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

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

Python version: 3.8.7 (default, Feb 10 2021, 09:04:08) [Clang 12.0.0 (clang-1200.0.32.29)] QGIS version: 3.16.4-Hannover Hannover, 81ba6c0826

Python Path: /Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python

Any help is very much appreciated!

danioxoli commented 3 years ago

hello,

It looks like the Pysal version used by QGIS is not 1.14 but superior. You can check directly from the python console of QGIS by typing:

import pysal
print(pysal.__version__)

then:

1) If by chance you have there pysal version 2.0, you can simply uninstall the plugin and install from zip this new version of the plugin which works with pysal 2.0: https://github.com/danioxoli/HotSpotAnalysis_Plugin/archive/qgis3pysal2.zip

2) If the version of pysal is instead actually 1.14, I suggest you to try to uninstall it from the terminal by typing:

python -m pip uninstall pysal

and the proceed with a new installation of pysal 2.0 like:

sudo pip3 install pysal==2.0.

I believe the problem can be solved with option 1) as pysal 2.0 should be already present in the MacOS QGIS.

let me know if this was useful.

best,

dbrosi commented 3 years ago

Thanks for the quick response! I went through all the steps that you said, but then came up with this message:

Couldn't load plugin 'HotSpotAnalysis_Plugin-qgis3pysal2' due to an error when calling its classFactory() method ModuleNotFoundError: No module named 'pysal.explore.esda'

However, I took the pysal 2.0 folder (that I knew was located in /Library/Frameworks/Python.framework/Versions/3.9/lib/ python3.9/site-packages through my terminal) and copied it into the folder /Applications/QGIS.app/Contents/ Resources/python and it worked!

So I think it was a combination of needing the new HotSpotAnalysis_Plugin that you provided me and placing it in the correct folder for QGIS to reach it.

Again, thanks for all of your help!

samueledward1997 commented 3 years ago

I have had the same issue, but for some reason have not had any luck. I am not experienced with python, but I have used R quite a bit. After uninstalling the plugin and reinstalling it using the link you provided, I get the error "Couldn't load plugin 'HotSpotAnalysis_Plugin-qgis3pysal2' due to an error when calling its classFactory() method"

I then followed the code you provided above and this was the result: import pysal Traceback (most recent call last): File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/code.py", line 90, in runcode exec(code, self.locals) File "", line 1, in File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 792, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/pysal/init.py", line 3, in from . import explore File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 792, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/pysal/explore/init.py", line 4, in import pointpats File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 792, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/pointpats/init.py", line 4, in from .pointpattern import PointPattern File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 792, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/pointpats/pointpattern.py", line 12, in from matplotlib import pyplot as plt File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 792, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/matplotlib-3.3.0-py3.8-macosx-10.13.0-x86_64.egg/matplotlib/pyplot.py", line 36, in import matplotlib.colorbar File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 792, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/matplotlib-3.3.0-py3.8-macosx-10.13.0-x86_64.egg/matplotlib/colorbar.py", line 44, in import matplotlib.contour as contour File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 792, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/matplotlib-3.3.0-py3.8-macosx-10.13.0-x86_64.egg/matplotlib/contour.py", line 17, in import matplotlib.text as text File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 792, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/matplotlib-3.3.0-py3.8-macosx-10.13.0-x86_64.egg/matplotlib/text.py", line 16, in from .textpath import TextPath # Unused, but imported by others. File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 792, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/matplotlib-3.3.0-py3.8-macosx-10.13.0-x86_64.egg/matplotlib/textpath.py", line 11, in from matplotlib.mathtext import MathTextParser File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 792, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/matplotlib-3.3.0-py3.8-macosx-10.13.0-x86_64.egg/matplotlib/mathtext.py", line 27, in from PIL import Image File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 792, in _import mod = _builtin_import(name, globals, locals, fromlist, level) File "/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/Pillow-7.2.0-py3.8-macosx-10.13.0-x86_64.egg/PIL/Image.py", line 94, in from . import _imaging as core File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/qgis/utils.py", line 792, in _import mod = _builtin_import(name, globals, locals, fromlist, level) ImportError: dlopen(/Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/Pillow-7.2.0-py3.8-macosx-10.13.0-x86_64.egg/PIL/_imaging.cpython-38-darwin.so, 2): Library not loaded: /opt/X11/lib/libxcb.1.dylib Referenced from: /Applications/QGIS-LTR.app/Contents/MacOS/lib/python3.8/site-packages/Pillow-7.2.0-py3.8-macosx-10.13.0-x86_64.egg/PIL/_imaging.cpython-38-darwin.so Reason: image not found print(pysal.version) Traceback (most recent call last): File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/code.py", line 90, in runcode exec(code, self.locals) File "", line 1, in NameError: name 'pysal' is not defined python -m pip uninstall pysal Traceback (most recent call last): File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/code.py", line 63, in runsource code = self.compile(source, filename, symbol) File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/codeop.py", line 178, in call return _maybe_compile(self.compiler, source, filename, symbol) File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/codeop.py", line 106, in _maybe_compile raise err1 File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/codeop.py", line 93, in _maybe_compile code1 = compiler(source + "\n", filename, symbol) File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/codeop.py", line 143, in call codeob = compile(source, filename, symbol, self.flags, 1) File "", line 1 python -m pip uninstall pysal ^ SyntaxError: invalid syntax sudo pip3 install pysal==2.0 Traceback (most recent call last): File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/code.py", line 63, in runsource code = self.compile(source, filename, symbol) File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/codeop.py", line 178, in call return _maybe_compile(self.compiler, source, filename, symbol) File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/codeop.py", line 106, in _maybe_compile raise err1 File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/codeop.py", line 93, in _maybe_compile code1 = compiler(source + "\n", filename, symbol) File "/Applications/QGIS-LTR.app/Contents/MacOS/../Resources/python/codeop.py", line 143, in call codeob = compile(source, filename, symbol, self.flags, 1) File "", line 1 sudo pip3 install pysal==2.0 ^ SyntaxError: invalid syntax

I'm very confused about what to do. I am sure the problem is with something that I am doing wrong, but I am unsure what it is. I am running this on a Mac on OS X 10.15.7 and using QGIS 13.6.5. Any help is appreciated. I was using the hotspot analysis plugin successfully about a month ago and now I am not having any luck.

dbrosi commented 3 years ago

Based on the issues I had with this package (and if I am reading your errors correctly), I think your problems are:

  1. You did not install the correct pysal package since both of the commands to change the pysal package have an invalid syntax error. For my Mac it worked when I used this command in the terminal app:

pip3 install pysal==2.0

  1. The pysal file that you do have is not in the right location. You need the pysal package to be in the within the python folder under the QGIS application. For my computer the pathway was: "/Applications/QGIS.app/Contents/ Resources/python", but it looks like yours might be slightly different so take that into consideration. When I was working on this, I couldn't figure out the code for terminal to get the pysal package into this folder, so I had to manually find where my terminal was placing the pysal package and place it into the python folder that I specified above under the name "pysal" for the code to run. The command below should tell you what pysal package version you have and where it is located:

pip3 show pysal

Again, I am not super well versed in code for python so there might be a much simpler way to do this than I am doing it, but it worked for me. @danioxoli, please feel free to correct me if you think anything I said above is incorrect.

Hope this helps!

danioxoli commented 3 years ago

Dear all, the manual solution proposed by @dbrosi worked also in my test. However, it is not much safe to move Py packages manually in general...

@samueledward1997, if both the solutions proposed in the readme and the manual one fail, try out to set QGIS paths to the package folder manually to be sure that the wanted packages are within the same python env used by QGIS (see: https://gis.stackexchange.com/questions/351280/installing-python-modules-for-qgis-3-on-mac)

Best