Can't find expat module; probably python path issue

1927
8
Jump to solution
09-05-2019 10:52 AM
MollyFoley
Regular Contributor

I'm trying to use the Excel to Table tool and I get a long error message that culminates in this:

No module named expat; use SimpleXMLTreeBuilder instead  

I have already repaired my ArcGIS installation and that didn't fix it so moving on... Now, I know the expat module exists in the Python 2.7 folder that ArcGIS is supposed to use. When I print the python path in the python window in ArcMap, I get this:

['', 
u'c:\\program files (x86)\\arcgis\\desktop10.7\\arcpy', 
'c:\\program files (x86)\\arcgis\\desktop10.7\\bin', 
'c:\\program files (x86)\\arcgis\\desktop10.7\\ArcPy', 
'c:\\program files (x86)\\arcgis\\desktop10.7\\ArcToolbox\\Scripts',
'C:\\WINDOWS\\SYSTEM32\\python27.zip',
'C:\\Users\\mfoley10\\AppData\\Local\\Continuum\\anaconda2\\Lib',
'C:\\Users\\mfoley10\\AppData\\Local\\Continuum\\anaconda2\\DLLs',
'C:\\Python27\\ArcGIS10.7\\Lib', 
'C:\\Python27\\ArcGIS10.7\\DLLs', 
'C:\\Python27\\ArcGIS10.7\\Lib\\lib-tk', 
'C:\\WINDOWS\\system32', 
'C:\\Python27\\ArcGIS10.7', 
'C:\\Python27\\ArcGIS10.7\\lib\\site-packages']‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I see that it's going into both Python27 folder and an anaconda2 folder. When I go to my registry keys though, I don't see a python 2.7 folder and instead I see 3.7. I have set up my python interpreter in Visual Studio to point to the Python 2.7 interpreter and it works there so all good in VS. It's just the problem in ArcMap. I'm not sure what to do from here. Do I change the Default, Executable, and Window Executable all to point to Python27? It's worth noting that all the other tools I've been using in ArcMap work fine, it's just this one that I've had problems with so far.

PythonPath folder has this in it:

The above screenshots are in the HKEY_LOCAL_MACHINE. When I go to HKEY_CURRENT_USER, these are the install and python paths which point to anaconda. Maybe these are the ones I need to change? The Visual Studio ones are correct because I have those pointing to the ArcGIS interpreter:

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
MollyFoley
Regular Contributor

So, I changed the path variables in the HKEY_CURRENT_USER (as seen in the original post, in the last two screenshots) to these:

InstallPath:

C:\Python27\ArcGIS10.7\‍

PythonPath:

C:\Python27\ArcGIS10.7\Lib;C:\Python27\ArcGIS10.7\DLLs\‍

It fixed the problem of being unable to use that tool so I'm going to tentatively say my answer is correct. However, I need to test with a few other things to see if I broke anything elsewhere...

View solution in original post

8 Replies
JoshuaBixby
MVP Esteemed Contributor

Type

help('modules')

in the Interactive Python window in ArcGIS Desktop and see if the module is listed as installed.

0 Kudos
MollyFoley
Regular Contributor

It does not appear that it is. I do see it in C:\Python27\ArcGIS10.7\Lib\xml\parsers, so I at least have it on my computer. Is there some piece of code I need to install it?

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

How did you try to install it the first time?  Obviously it got installed with one or more of the Python interpreters on your machine, just not the one bundled with ArcGIS Desktop.

0 Kudos
MollyFoley
Regular Contributor

Correct. It's been a while since I installed these things, but I think my order was Visual Studio, ArcGIS, Anaconda (Jupyter). I didn't install anything through command prompts, just through installing various software via GUI. I have never needed to mess with any of my python path variables until now, even though I'm not 100% that it's the problem. ArcMap does seem to use Python27 otherwise no geoprocessing tools would work considering they all run on arcpy. It's just this one tool.

I wonder if I did 'pip install expat' in a windows cmd prompt if it would work.

Edit: I fixed it. See my answer below.

0 Kudos
MollyFoley
Regular Contributor

So, I changed the path variables in the HKEY_CURRENT_USER (as seen in the original post, in the last two screenshots) to these:

InstallPath:

C:\Python27\ArcGIS10.7\‍

PythonPath:

C:\Python27\ArcGIS10.7\Lib;C:\Python27\ArcGIS10.7\DLLs\‍

It fixed the problem of being unable to use that tool so I'm going to tentatively say my answer is correct. However, I need to test with a few other things to see if I broke anything elsewhere...

JoeBorgione
MVP Esteemed Contributor

Following this thread from the sidelines: I have ArcGIS 10.6 installed as well as Pro 2.4 and a couple of python envs.  I don't see the expat.py when I try what Joshua suggests either, and I see it in the same folder (under 10.6) as you mention.  However, I've never had a problem with excel to table, either the tool or running it within a script.  I just ran it before typing this response and sure enough, I got the table no problem.

Sorry this doesn't help resolve your situation, but it sure is a strange one...

That should just about do it....
0 Kudos
MollyFoley
Regular Contributor

I just fixed it. I don't know if it's broken anything else but I'm tentatively saying that changing the python paths for HKEY_CURRENT_USER (last two screenshots in the original post) to the Python27 paths fixed it.

You are correct though, expat still does not show up in the modules for me even though everything seems to be working now. Very curious indeed.

Edit: It has not broken anything else. I checked my scripts in PyCharm, Visual Studio, and Jupyter Notebooks and everything is working.

JoeBorgione
MVP Esteemed Contributor

Glad you got it figured out!

That should just about do it....
0 Kudos