Spatial Statistics: Mean Center tool failed to work

1759
6
09-06-2017 05:41 PM
NaAn1
by
New Contributor II

Hi,

I need to generate the weighted centroid point using Mean Center tool. But it failed with the following error:

arcpy.MeanCenter_stats('Zip5_all_air', r'C:\Users\nanamzn\Documents\ArcGIS\Default.gdb\Zip3_MeanCenter', 'PackageNumber', '#', '#')
Runtime error  Traceback (most recent call last):   File "<string>", line 1, in <module>   File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\stats.py", line 1231, in MeanCenter     raise e ExecuteError:  Traceback (most recent call last):   File "c:\program files (x86)\arcgis\desktop10.5\ArcToolbox\Scripts\MeanCenter.py", line 25, in <module>     import SSUtilities as UTILS   File "c:\program files (x86)\arcgis\desktop10.5\ArcToolbox\Scripts\SSUtilities.py", line 29, in <module>     import matplotlib.path as PATH   File "C:\Python27\ArcGIS10.5\lib\site-packages\matplotlib\__init__.py", line 129, in <module>     from matplotlib.externals.six.moves.urllib.request import urlopen   File "C:\Python27\ArcGIS10.5\lib\site-packages\matplotlib\externals\six.py", line 90, in __get__     result = self._resolve()   File "C:\Python27\ArcGIS10.5\lib\site-packages\matplotlib\externals\six.py", line 158, in _resolve     module = _import_module(self.mod)   File "C:\Python27\ArcGIS10.5\lib\site-packages\matplotlib\externals\six.py", line 80, in _import_module     __import__(name)   File "C:\Anaconda2\Lib\urllib2.py", line 94, in <module>     import httplib   File "C:\Anaconda2\Lib\httplib.py", line 72, in <module>     import socket   File "C:\Anaconda2\Lib\socket.py", line 47, in <module>     import _socket ImportError: DLL load failed: %1 is not a valid Win32 application.  Failed to execute (MeanCenter).  

I uninstalled Anaconda2 from my machine and rerun the tool. It failed again with different error. May I ask how to fix the problem?


>>> arcpy.MeanCenter_stats('Zip5_all_air', r'C:\Users\nanamzn\Documents\ArcGIS\Default.gdb\Zip3_MeanCenter1', 'PackageNumber', '#', '#')
Runtime error  Traceback (most recent call last):   File "<string>", line 1, in <module>   File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\stats.py", line 1231, in MeanCenter     raise e ExecuteError:  Traceback (most recent call last):   File "c:\program files (x86)\arcgis\desktop10.5\ArcToolbox\Scripts\MeanCenter.py", line 25, in <module>     import SSUtilities as UTILS   File "c:\program files (x86)\arcgis\desktop10.5\ArcToolbox\Scripts\SSUtilities.py", line 29, in <module>     import matplotlib.path as PATH   File "C:\Python27\ArcGIS10.5\lib\site-packages\matplotlib\__init__.py", line 1138, in <module>     rcParams = rc_params()   File "C:\Python27\ArcGIS10.5\lib\site-packages\matplotlib\__init__.py", line 971, in rc_params     fname = matplotlib_fname()   File "C:\Python27\ArcGIS10.5\lib\site-packages\matplotlib\__init__.py", line 800, in matplotlib_fname     configdir = _get_configdir()   File "C:\Python27\ArcGIS10.5\lib\site-packages\matplotlib\__init__.py", line 655, in _get_configdir     return _get_config_or_cache_dir(_get_xdg_config_dir())   File "C:\Python27\ArcGIS10.5\lib\site-packages\matplotlib\__init__.py", line 580, in _get_xdg_config_dir     path = get_home()   File "C:\Python27\ArcGIS10.5\lib\site-packages\matplotlib\__init__.py", line 320, in wrapper     ret = func(*args, **kwargs)   File "C:\Python27\ArcGIS10.5\lib\site-packages\matplotlib\__init__.py", line 522, in _get_home     path = os.path.expanduser(b"~").decode(sys.getfilesystemencoding()) LookupError: unknown encoding: mbcs  Failed to execute (MeanCenter).

Thanks a lot!

Anna

Tags (1)
0 Kudos
6 Replies
NaAn1
by
New Contributor II

When running the following script in windows command line. It works:

import arcpy
... arcpy.MakeFeatureLayer_management(r'C:\ArcGIS_data_analysis\test.gdb\Zip5', "Zip5_point_lyr")
... arcpy.MeanCenter_stats('Zip5_point_lyr', r'C:\ArcGIS_data_analysis\Centroid_analysis\Centroid.gdb\test', 'PackageNumber', 'Zip3', 'PackageNumber')

Why does this happen?

0 Kudos
DanPatterson_Retired
MVP Emeritus

Sounds like you have a couple of versions of python lurking around.

ArcMap uses 2.7 32bit and your command line prompt should look like this

make sure you don't have a 64 bit version installed.

To be sure, you can uninstall all versions of python then do a repair installation of ArcMap to get the right python installed in the C:\Python27\ArcGIS10.5.... file location

To get python 3.x, install ArcGIS Pro, it sets up a conda distribution separate from other version of python

curtvprice
MVP Esteemed Contributor

Dan is absolutely right, this is a Python issue, not a issue with the tool. I suspect you have some non-ArcGIS versions of Python installed that messed with the paths. The issue really is how weak Windows is with how it handles paths.  The way most people get into this trouble is when they install Anaconda and neglect to un-check the boxes that modify the Windows environment. A sure way to break the Windows setup ArcGIS needs to properly communicate with the correct Python executables and environment.

The fix is to go to Add/Remove programs and remove any Python installs you see, then run a repair install of ArcGIS Desktop (and ArcGIS 64 bit Background Processing, and Pro, if that's installed too). This will get you on the true Python path.

NaAn1
by
New Contributor II

Thanks Dan and Curtis. After I removed the python installed by Anaconda, the tool worked! Thank you!

curtvprice
MVP Esteemed Contributor

Great! I was inspired to create a blog post that hopefully will come in future searches by others feeling similar pain.

https://community.esri.com/people/curtvprice/blog/2017/09/07/python-tool-fails-with-not-a-valid-win3...

0 Kudos
MajaTurkalj
New Contributor

I have just run on the same issue. Just to let you know that I had removed all other Python installs and keep the one ArcMap is using. I have run the Mean Center again and it worked. I did not even have to run a repair install of ArcGIS Desktop. Thanks for help

0 Kudos