danioxoli / HotSpotAnalysis_Plugin

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

AttributeError: 'array.array' object has no attribute 'fromstring' #72

Closed smuurling closed 2 years ago

smuurling commented 2 years ago

Thanks so much for this plugin Daniele, I really hope that I will get it to work. I am working with QGIS 3.20.2, have pysal 2.0.0 installed, and was able to obtain the plugin through the Plugin tab in QGIS. Still, I get this error. Do you have any ideas on how I can get it to work? (Like install python 3.7 or something?)

Traceback (most recent call last): File "C:\Users/Sawna/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\HotspotAnalysis\hotspot_analysis.py", line 612, in run w = Queen.from_shapefile(layerName.split("|")[0]) File "C:\Users\Sawna\AppData\Roaming\Python\Python39\site-packages\pysal\lib\weights\contiguity.py", line 236, in from_shapefile w = cls(FileIO(filepath), ids=ids, *kwargs) File "C:\Users\Sawna\AppData\Roaming\Python\Python39\site-packages\pysal\lib\weights\contiguity.py", line 182, in init neighbors, ids = _build(polygons, ids=ids, File "C:\Users\Sawna\AppData\Roaming\Python\Python39\site-packages\pysal\lib\weights\contiguity.py", line 385, in _build neighbor_data = ContiguityWeightsLists(polygons, wttype=wttype).w File "C:\Users\Sawna\AppData\Roaming\Python\Python39\site-packages\pysal\lib\weights_contW_lists.py", line 53, in init self.collection = list(collection) File "C:\Users\Sawna\AppData\Roaming\Python\Python39\site-packages\pysal\lib\io\fileio.py", line 254, in next r = self.read() File "C:\Users\Sawna\AppData\Roaming\Python\Python39\site-packages\pysal\lib\io\fileio.py", line 315, in read row = self._read() File "C:\Users\Sawna\AppData\Roaming\Python\Python39\site-packages\pysal\lib\io\iohandlers\pyShpIO.py", line 140, in _read rec = self.dataObj.get_shape(self.pos) File "C:\Users\Sawna\AppData\Roaming\Python\Python39\site-packages\pysal\lib\io\util\shapefile.py", line 362, in get_shape return self.shape.unpack(bufferIO(self.fileObj.read(byts))) File "C:\Users\Sawna\AppData\Roaming\Python\Python39\site-packages\pysal\lib\io\util\shapefile.py", line 636, in unpack _unpackDict2(record, contentStruct, dat) File "C:\Users\Sawna\AppData\Roaming\Python\Python39\site-packages\pysal\lib\io\util\shapefile.py", line 155, in _unpackDict2 result.fromstring(fileObj.read(result.itemsize n)) AttributeError: 'array.array' object has no attribute 'fromstring'

smuurling commented 2 years ago

Actually, your comment below worked for me! https://github.com/danioxoli/HotSpotAnalysis_Plugin/issues/64#issuecomment-907174436

danioxoli commented 2 years ago

I was exactly pointing you at that.

Thank you for anticipating me!

RafP2021 commented 1 year ago

Hi Daniele, Thank you so much for your efforts in maintaining HA plugin.

I use QGIS 3.22.4 with PySAL 2.0 and I run the last version of Hotspot Analysis, however, I keep getting an error identical to that of this topic's opener ('array.array' object has no attribute 'fromstring').


AttributeError: 'array.array' object has no attribute 'fromstring' Traceback (most recent call last): File "C:\Users/humbo/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\HotSpotAnalysis_Plugin-qgis3pysal2\hotspot_analysis.py", line 612, in run w = Queen.from_shapefile(layerName.split("|")[0]) File "C:\Users\humbo\AppData\Roaming\Python\Python39\site-packages\pysal\lib\weights\contiguity.py", line 236, in from_shapefile w = cls(FileIO(filepath), ids=ids, *kwargs) File "C:\Users\humbo\AppData\Roaming\Python\Python39\site-packages\pysal\lib\weights\contiguity.py", line 182, in init neighbors, ids = _build(polygons, ids=ids, File "C:\Users\humbo\AppData\Roaming\Python\Python39\site-packages\pysal\lib\weights\contiguity.py", line 385, in _build neighbor_data = ContiguityWeightsLists(polygons, wttype=wttype).w File "C:\Users\humbo\AppData\Roaming\Python\Python39\site-packages\pysal\lib\weights_contW_lists.py", line 53, in init self.collection = list(collection) File "C:\Users\humbo\AppData\Roaming\Python\Python39\site-packages\pysal\lib\io\fileio.py", line 254, in next r = self.read() File "C:\Users\humbo\AppData\Roaming\Python\Python39\site-packages\pysal\lib\io\fileio.py", line 315, in read row = self._read() File "C:\Users\humbo\AppData\Roaming\Python\Python39\site-packages\pysal\lib\io\iohandlers\pyShpIO.py", line 140, in _read rec = self.dataObj.get_shape(self.pos) File "C:\Users\humbo\AppData\Roaming\Python\Python39\site-packages\pysal\lib\io\util\shapefile.py", line 362, in get_shape return self.shape.unpack(bufferIO(self.fileObj.read(byts))) File "C:\Users\humbo\AppData\Roaming\Python\Python39\site-packages\pysal\lib\io\util\shapefile.py", line 636, in unpack _unpackDict2(record, contentStruct, dat) File "C:\Users\humbo\AppData\Roaming\Python\Python39\site-packages\pysal\lib\io\util\shapefile.py", line 155, in _unpackDict2 result.fromstring(fileObj.read(result.itemsize n)) AttributeError: 'array.array' object has no attribute 'fromstring'

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

Elsewhere, (https://github.com/danioxoli/HotSpotAnalysis_Plugin/issues/64#issuecomment-907174436) you were suggesting to manually substitute fromstring method with frombytes.

As I'm very basic with python, can I ask you how to correctly do this manual substitution? Thank you!

danioxoli commented 1 year ago

It is not clear why the error persists with PySAL > 2 but you can try the same correction by opening from your folder browser the path "C:\Users\humbo\AppData\Roaming\Python\Python39\site-packages\pysal\lib\io\util". Once in the folder, look for "shapefile.py" file and open it with a text editor to make the suggested correction. Just remember to save the change at the end.

RafP2021 commented 1 year ago

Thank you! Now it works!