Matplotlib for Python scripting in ArcGIS 10 does not work

6360
21
06-29-2011 12:50 PM
wernerrolf
New Contributor
I use ArcGIS 10 and would like to run Matplotlib to create charts within a python script. Therefore I have installed
- numpy-1.6.1rc1-win32-superpack-python2.6.exe
- matplotlib-1.0.1.win32-py2.6.exe

as noted here: http://matplotlib.sourceforge.net/users/installing.html

If I test a script to check the installation like:

import numpy
arcpy.AddMessage("NUMPY Version " + numpy.__version__)

import matplotlib
arcpy.AddMessage("MATPLOTLIB Version " + matplotlib.__version__)

I get the following error:
Running script Script...
NUMPY Version 1.6.1rc1
<type 'exceptions.AttributeError'>: 'module' object has no attribute '__version__'
Failed to execute (Script).

Also the command
- import pylab as pl

leads to the error
<type 'exceptions.ImportError'>: No module named pylab
Failed to execute (Script).


So even matplotlib is installed properly in the directory "site-packages" (see screenshot of directory structure attached) it does not work in ArcGIS.


By the way if I let it run in iPython (same installation) it works perfect.

What still needs to be done to get matplotlib work in ArcGIS 10?

Thanks
Werner
Tags (2)
0 Kudos
21 Replies
ChrisBater
New Contributor II
No sure if this will help at this point, but here are instructions that I put together to install python(x,y). Stuart's little plotting script works fine for me in IDLE, Spyder, and Arc's Python window.



1) Install ArcGis10 without python or uninstall python
2) Download Python(x,y) from http://www.pythonxy.com/ and install, making sure you select "custom directories" so that python is installed in C:\Python26. If installing on a 64 bit machine, do not include GDAL 1.6 �?? it won�??t work. Instead, go to http://www.lfd.uci.edu/~gohlke/pythonlibs/ and install  GDAL-1.8.0.win32-py2.6.exe.
3) Create a file called Desktop10.pth, which  should contain these lines:
C:\Program Files (x86)\ArcGIS\Desktop10.0\bin
C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy
C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Script
4) Place the file in the python installation directory: �??C:\Python26�??
5) Open IDLE and try �??import arcpy�??
0 Kudos
V_StuartFoote
MVP Frequent Contributor
Chris,

Yes that is the direction for using an alternate Python instance. The problem remains ArcGIS 10 ArcPy compiled PYC (DCOM against ArcObjects) dependencies on a hard coded numpy-1.3 instance.

While it was his original question, we'll cook Werner's noodle if we drag him down that path.

For now I'd like to see him get a functional matplotlib site-package install that works with both an ArcGIS 10 Python window--in process--, as well as in a Python IDE or command line for doing the plotting and MATLAB like processing of his geospatial data.

The Python(X, Y) install is an open question over on the GIS Stack Exchange and this one.  But your note on GDAL 1.6 vs 1.8 version and past comments on numpy-1.3 dependencies of the ArcPy site-package mean there is a lot to be worked out. What GDAL release does ESRI use in ArcPy? 

Stuart
0 Kudos
ChrisBater
New Contributor II
Fair enough. Sorry if I'm sowing mass confusion. Interestingly, I'm running numpy version 1.5.1 and have had no issues. (Yet.)
0 Kudos
wernerrolf
New Contributor
As my noodles are not cooked yet I was as well considering to try it with Python(x,y) - so it's not really confusing but an option. But somewhere else I read the same about that ArcGIS gets problem with numby newer than 1.3.

Maybe it's a try worth...
0 Kudos
wernerrolf
New Contributor
Chris,

but if I install Python(x,y) don't I have to install it in a directory namend C:\Python26\ArcGIS10.0\
as this is the default when ArcGIS installed python2.6?

Thanks
0 Kudos
ChrisBater
New Contributor II
but if I install Python(x,y) don't I have to install it in a directory namend C:\Python26\ArcGIS10.0\
as this is the default when ArcGIS installed python2.6?


Hi Werner,

Don't install python in  C:\Python26\ArcGIS10.0\. The safest way to start off is probably to completely uninstall arc, then reinstall it without python. Then install python(x,y) in �??C:\Python26�?? and deal with the gdal issue, if necessary. From there, I'll direct you to steps 3 and 4 in my 'Python (x,y) installation instructions:'

3) Create a file called Desktop10.pth, which should contain these lines:
C:\Program Files (x86)\ArcGIS\Desktop10.0\bin
C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy
C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Script
4) Place the file in the python installation directory: �??C:\Python26�??

The Desktop10.pth file will point to the required directories.

If there are issues with using a version of numpy other than 1.3, I haven't encountered them, and frankly, the benefits of having libraries like matplotlib and scipy work properly far outweigh the risks when arc is already such an unreliable bit of software.

Obviously I can't provide a warranty with this, but it works for me and I haven't looked back. Esri really needs to reevaluate it's python distribution so that it can play nice with the wider community, otherwise, what's the point?

I apologize for the rant. Good luck!

Chris
0 Kudos
CHRISCLASEN
New Contributor
Chris Bater, any ideas on how this would work with Arc10.1? Will it only work with Python 2.6.x installed?

I added Desktop10.1.pth to my C:\Python27 directory

C:\Program Files (x86)\ArcGIS\Desktop10.1\bin
C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy
C:\Program Files (x86)\ArcGIS\Desktop10.1\ArcToolbox\Script   #note that this directory doesn't exist

Still no luck. I'd like to develop in Spyder by using arcpy and numpy.

Thanks,

Chris
0 Kudos
ShaunWalbridge
Esri Regular Contributor
On my 10.1 install, Spyder 2.2 installs without problems and is directly usable with arcpy without any path changes necessary.

cheers,
Shauin
0 Kudos
SamuelMcDeid
New Contributor II
On my 10.1 install, Spyder 2.2 installs without problems and is directly usable with arcpy without any path changes necessary.

cheers,
Shauin


How did you install Spyder? I get an error stating that Spyder can't find an installation of python whenever I use the .exe.
0 Kudos
ShaunWalbridge
Esri Regular Contributor
Samuel,

The spyder.bat file just includes a reference to "python", without the full path to the executable. You can fix it by either adding the path to your Python installation to your system PATH variable (see this post), or by changing the spyder.bat file to include the full location of python.exe, something like
C:\Python27\ArcGIS10.2
.
0 Kudos