Select to view content in your preferred language

Beginner having trouble importing arcpy

3998
5
Jump to solution
01-28-2014 07:56 AM
by Anonymous User
Not applicable
Original User: ekociuk

Hey everybody, I am looking at python for my first time ever, trying to follow a tutorial to create a shapefile for each unique value in my attribute table for a specific field. The tutorial suggests I write that start of my code like this:


import arcpy

shpfile = "D:\\GIS\\Python_Exparament\\TEST_YEARS.shp"

cursor = arcpy.SearchCursor(shpfile)

for row in cursor:
    print row.YEAR



After I write that section I get an error message saying:

Traceback (most recent call last):
  File "D:/GIS/Python_Exparament/py_script.py", line 1, in <module>
    import arcpy, OS
ImportError: No module named arcpy


Does anybody have any idea why such a message is coming up?

Thanks for your time.
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
Original User: hua17

Hello Eric,

Good looking script so far!

I'd start by making sure you are using the right version of python on your machine (I've had this problem many times). It is possible that you have two installs. I would go to the start menu > All Programs > ArcGIS > Python 2.7 > IDLE (Python GUI) and use that version IDLE to run your script. (Note you may have a different version of python)

On an unrelated note: The error message looks like you have the line "import arcpy, OS" in your script. It's not necessary, but it is good practice to have that on two lines: (also, change "OS" to "os")
import arcpy import os


Let me know if that works or not! Good luck!

View solution in original post

0 Kudos
5 Replies
MichaelVolz
Esteemed Contributor
What version of ArcGIS Desktop are you using?

What is your operating system?

A couple of questions to start to get a background about your problem.
0 Kudos
by Anonymous User
Not applicable
Original User: ekociuk

Version 10.1 and Windows 7
0 Kudos
MichaelVolz
Esteemed Contributor
Are you running this script in IDLE?
0 Kudos
by Anonymous User
Not applicable
Original User: hua17

Hello Eric,

Good looking script so far!

I'd start by making sure you are using the right version of python on your machine (I've had this problem many times). It is possible that you have two installs. I would go to the start menu > All Programs > ArcGIS > Python 2.7 > IDLE (Python GUI) and use that version IDLE to run your script. (Note you may have a different version of python)

On an unrelated note: The error message looks like you have the line "import arcpy, OS" in your script. It's not necessary, but it is good practice to have that on two lines: (also, change "OS" to "os")
import arcpy import os


Let me know if that works or not! Good luck!
0 Kudos
by Anonymous User
Not applicable
Original User: ekociuk

Thank you for the help everybody, Got er working good. It is much appreciated!! 🙂
0 Kudos