I need help with this error

3723
5
10-21-2014 02:03 PM
TrevorFugate
New Contributor

Traceback (most recent call last):

  File "C:\Python27\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript

    exec codeObject in __main__.__dict__

  File "E:\GEO501\Exercise07\Results\printvalues.py", line 1, in <module>

    import arcpy

ImportError: No module named arcpy

Here is the code:

import arcpy

from arcpy import env

env.workspace = "C:/EsriPress/Python/Data/Exercise07"

fc = "airports.shp"

cursor = arcpy.da.SearchCursor(fc, ["NAME"])

for row in cursor:

print "Airport name = {0}".format(row[0])

Tags (3)
0 Kudos
5 Replies
JasonScheirer
Occasional Contributor III

Is ArcGIS installed on your machine? Which version? Did you install Python yourself?

0 Kudos
TrevorFugate
New Contributor

Yes for both.

0 Kudos
TrevorFugate
New Contributor

ArcGis 10.1 and python 2.7

0 Kudos
JasonScheirer
Occasional Contributor III

That is probably the problem. You installed Python after installing ArcGIS? You've probably messed up your installation now, you may want to uninstall both and reinstall just ArcGIS.

As a hack, you may be able to run C:\Python27\ArcGIS10.1\python.exe right now. If it won't import arcpy, then you'll need to do the reinstallation first. But python.exe will live in C:\Python27\ArcGIS10.1\, not C:\Python27\ after you've installed ArcGIS.

ToddJackson2
New Contributor II

Hi Trevor,

As Jason said, the existence of both python installations is the most likely cause of the issue.  What you could try doing before attempting a reinstall of ArcGIS is set some python directories in your PATH to see if that solves the problem

To set your PATH variable in Windows, go to Start >> Control Panel >> System, click Advanced System Settings, click the Environment Variables button in the lower part of the Advanced tab.

In the System variables section in the lower part of the form, scroll through until you find the Path variable.

Make sure that there are no values pointing to the C:\Python27 directory, if so delete those parts (between the semi colons).  Add the following to the end of your Path variable -

C:\Python27\ArcGIS10.2\;C:\Python27\ArcGIS10.2\Scripts\

This should be enough to allow calls to python to use the ArcGIS embedded python instance by default.

I notice one exception you are seeing is coming from the PyWin module.  It may have also been affected by the two python installations.  Try installing PyWin32 again, and make sure during the installation that it finds the ArcGIS embedded python environment to install into.

Cheers,

Todd

0 Kudos