ArcPy not recognized in Python Window inside ArcMap

7776
4
01-15-2014 11:41 AM
KristianEkenes1
New Contributor
This has been a source of incredible frustration for me for the last couple of days. For some reason no IDEs nor ArcMap recognize arcpy. I've been learning Python through online tutorials over the last couple of weeks without issues. The scripts I wrote inside the Python window of ArcMap have worked just fine -- until a couple of days ago.

I recently began a tutorial that encouraged scripting in PythonWin. So I installed Python 2.6 and PythonWin on my machine. But for some reason PythonWin wouldn't open, so I installed Python 2.7. It opened, but when I attempted to import arcpy, I was given this error:

"ImportError: No module named arcpy"

The same error appeared in IDLE and PyScripter. So I reopened the Python Window in ArcMap and arcpy wasn't recognized there eighter! It printed this message:

"NameError: name 'arcpy' is not defined"

I'm also unable to write expressions in the calculator with Python because it doesn't recognize the code. Does anyone know how I can fix this? Your help is much appreciated.
Tags (2)
0 Kudos
4 Replies
Luke_Pinner
MVP Regular Contributor
Installing other versions of python is what messed up arcpy.  You don't need to install other versions, you can use PyScripter/Pythonwin with whatever version of python is already installed.

What version of ArcGIS are you using?
0 Kudos
KristianEkenes1
New Contributor
I'm using ArcGIS 10.2. But you're right, the installations messed it up. Re-installing ArcMap (repair) fixed the problem.
0 Kudos
RatzzyRatz
New Contributor

I ran into the same 'arcpy' is not defined error after installing ArcGIS 10.2.1 for Desktop along with the Background Geoprocessing (64-bit).

Originally I had installed PyScripter after Pythonwin stopped working.  But then I had problems running tools in ArcMap.

What I found that fixed things.  I needed to reinstall Python for Windows Extensions for the new version of Python that was included with 10.2.1.

Start here:

http://sourceforge.net/projects/pywin32/files/pywin32/

Click on the latest Build (currently Build 219)

Download the two versions (32-bit and 64-bit) for your current Python version (2.7)

I clicked on the following items to download.  Note, sometimes the download page didn't work until I clicked on the "direct link" option at the top of the page.

  • pywin32-219.win-amd64-py2.7.exe
  • pywin32-219.win32-py2.7.exe

You can kind of see which versions are the most downloaded by the little graph to the right.

Now it's important to install the 64 bit version first, then the 32 bit version.  Otherwise you'll get "can't find arcpy" messages when you try to run scripts.

Run the pywin32-219.win-amd64-py2.7.exe version first and let that install.

I got an error message that said the following, but it DID finish:

close failed in file object destructor:

sys.excepthook is missing

lost sys.stderr

Then run the pywin32-219.win32-py2.7.exe version and let that install.

I got the same error message as above again.

Now I was able to right click a .py script and "Edit with Pythonwin" and run things with no problem.

0 Kudos
KateDoughty1
New Contributor III

I just ran into this issue where Table to Excel tool wouldn't work, nor would ArcPy within ArcMap version 10.3.1. Before uninstalling ArcGIS for Desktop, I downloaded the Install available on My Esri and selected Repair (hoping to reduce the time on this troubleshoot). The repair tool approximately minutes 20 minutes. Both Table to Excel and ArcPy are working without issue.

0 Kudos