Select to view content in your preferred language

Making a Python script run as a stand alone script

7292
4
Jump to solution
06-10-2015 05:52 AM
BenSimpson
Deactivated User

Hi there,

I have exported a python script from model builder and I am now trying to make that script run as a stand alone script. The script in question is using the CreateFileGDB tool, CreateFeatureDataset tool and FeatureClassToGeodatabase tool. I am currently getting an ImportError: No module named arcpy. I am very new to python and I am going to have to create stand alone scripts for everything I do in ArcGIS for this project so I would be very grateful for any help or advise on the subject. I am using ArcGIS 10.3.1 and Python 2.7.8. The code and results are provided below.

# Import arcpy module
import arcpy


# Local variables:
v1km_grid_Eng_Wales_shp = "D:\\16426-0\\NVZstats_spatial_data\\1km_grid\\1km_grid_Eng_Wales.shp"
Eng_2010_land_cover_local_shp = "D:\\16426-0\\NVZstats_spatial_data\\LandUse_Cover\\Eng_2010_land_cover_local.shp"
rbcv16_shp = "D:\\16426-0\\NVZstats_spatial_data\\WFD_WBs_cycle1\\rbcv16.shp"
Python_Tests = "D:\\Python Training\\Python Tests"
GDB_Test_v1_gdb = Python_Tests
Shapefiles = "D:\\Python Training\\Python Tests\\GDB_Test_v1.gdb\\Shapefiles"
Shapefiles__2_ = Shapefiles


# Process: Create File GDB
arcpy.CreateFileGDB_management(Python_Tests, "GDB_Test_v1.0", "9.3")


# Process: Create Feature Dataset
arcpy.CreateFeatureDataset_management(GDB_Test_v1_gdb, "Shapefiles", "PROJCS['British_National_Grid',GEOGCS['GCS_OSGB_1936',DATUM['D_OSGB_1936',SPHEROID['Airy_1830',6377563.396,299.3249646]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',400000.0],PARAMETER['False_Northing',-100000.0],PARAMETER['Central_Meridian',-2.0],PARAMETER['Scale_Factor',0.9996012717],PARAMETER['Latitude_Of_Origin',49.0],UNIT['Meter',1.0]];-5220400 -15524400 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision")


# Process: Feature Class to Geodatabase (multiple)
arcpy.FeatureClassToGeodatabase_conversion("D:\\16426-0\\NVZstats_spatial_data\\1km_grid\\1km_grid_Eng_Wales.shp;D:\\16426-0\\NVZstats_spatial_data\\LandUse_Cover\\Eng_2010_land_cover_local.shp;D:\\16426-0\\NVZstats_spatial_data\\WFD_WBs_cycle1\\rbcv16.shp", Shapefiles)

Here is the error:

Traceback (most recent call last):
  File "D:\Python Training\Test_GDB2.py", line 10, in <module>
    import arcpy
ImportError: No module named arcpy

Any help in fixing this code would be much appreciated. I hope I have provided all the information that you need, if not please let me know.

Ben.

0 Kudos
1 Solution

Accepted Solutions
ToddBlanchette
Frequent Contributor

Hi Ben,

This issue arises if you're using a Python distribution that wasn't installed by the ArcGIS installation process.  The distribution won't have access to the arcpy modules by default as they are provided by ArcGIS and not Python, so one solution is to copy them over yourself.

See the section titled "Accessing Arcpy functions from another Python" in the following link:

Locating Python, adding to Path and accessing Arcpy | Python, GIS and stuff...

Also some other good general Python installation notes there, especially with including your Python path in the Windows path listings.

Cheers,

Todd

View solution in original post

4 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Ben,

Do you have ArcGIS Desktop installed on the machine you are trying to run the script from?

ToddBlanchette
Frequent Contributor

Hi Ben,

This issue arises if you're using a Python distribution that wasn't installed by the ArcGIS installation process.  The distribution won't have access to the arcpy modules by default as they are provided by ArcGIS and not Python, so one solution is to copy them over yourself.

See the section titled "Accessing Arcpy functions from another Python" in the following link:

Locating Python, adding to Path and accessing Arcpy | Python, GIS and stuff...

Also some other good general Python installation notes there, especially with including your Python path in the Windows path listings.

Cheers,

Todd

KipoKipo
Occasional Contributor

Thank you so much for this! I've been looking for solving this for a while and finally landed here.

KP

0 Kudos
BSplitt
Emerging Contributor

It appears that the link in this answer is broken. Does anyone have an updated link? 

0 Kudos