0

I'm working on the python for everyone lab in Esri's Virtual campus. I'm running into an issue that I can't seem to solve, I've already done some outside research hence posting here!

The issue:

4th Lab "Use python in ArcGIS" Step 5, when I run the code I'm getting this error:

Runtime error
Traceback (most recent call last):
  File "<string>", line 3, in <module>
NameError: name 'arcpy' is not defined

My code seems to looks fine, I've doubled checked multiple times this is what it looks like:

>>> # Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script
... # The following inputs are layers or table views: "RI_Schools", "Providence"
... arcpy.Clip_analysis("RI_Sewers","Providence","C:/Users/Laura.Ye/Documents/GIS & RS Labs/GIS II Project Folder/Assignment 1/PythEveryone10_1/PythonInArcGIS/sewers.shp","#")
... 
Runtime error 
Traceback (most recent call last):
  File "<string>", line 3, in <module>
NameError: name 'arcpy' is not defined
>>> 

I added an import arcpy statement as my first line of script but didn't get to far because I received the following:

import arcpy Runtime error Traceback (most recent call last): File "", line 1, in File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy__init__.py", line 24, in from arcpy.toolbox import * File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\toolbox.py", line 351, in from management import Graph, GraphTemplate File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 22, in import _management File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy_management.py", line 14, in import _graph File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy_graph.py", line 27, in import numpy ImportError: No module named numpy

** This import error occurred earlier except that time it said "No module named arcpy"

Overall, I've been having a number of errors and issues, and it seems like I should remove/reinstall ArcGIS and Python. Both seem to be located in two different locations on my computer. One location is the C:\ and the other is C:\users. I'm looking in the property files for both, the first has 6,145 files and 33 folders while the second has 63 files and 3 folders.

A little more background:

Within the first folder location C:(labeled ArcGIS10.2) there's a Python folder and a bunch of other folders. Also, there is a separate folder not nested with the ArcGIS10.2 folder, but alongside labeled Python27, which contains 5,477files and 249folders.

Within the second folder location, C:\users\ (labeled ArcGIS) there's a pywin32-218.win-amd64-py2.7 application file.

My conclusion:

This all seems like an unorganized mess, so I'm tempted to delete everything and start over. I'm new to using Python but have used ArcGIS over the last year and a half so when I first installed everything I didn't pay much attention to Python. About 2 months ago I slowly started to begin learning Python, outside of the ArcGIS environment, and downloaded a version of Python2.7. Now that I have a little more experience with GIS etc. I'm much better at trouble shooting and figuring things out, but this seems like a crazy mess of unorganized and broken files/programs etc.!

I am due for an upgrade to ArcGIS 10.3 (with my student license) so perhaps starting fresh would be easier than trying to fix everything. At least then I would have a better idea if what I encounter is user error or something else.

Any thoughts?

  • If anyone else experiences this issue I found this thread to be helpful geonet.esri.com/thread/102653. – CrunchTech78 Jan 31 '16 at 15:26
  • Symptoms like these which are all over the place definitely suggest to me that an uninstall/reinstall is warranted, and will be the expedient to getting your environment operating again. – PolyGeo Mar 22 '16 at 22:17
3

Add an import arcpy statement as the first line of your script.

Because you can't import arcpy, you have an installation error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.