No Module Named GIS
from arcgis.gis import GIS
ImportError: No module named gis
I am getting the following error when trying to run my python script. I currently have the ArcGIS for Python API installed from ArcGIS Pro 2.0. This was installed for all users on my machine. I am trying to run my script below in the Python IDLE 2.7.12. I'm not sure why the module will not load. I have seen other posts about rearranging folders and possibly having to run this as administrator if the Python API was installed for all users on a specific machine. I'm running the script from the network and not my local drive. Any ideas???
# ---------------------------------------------------------------------------
# Script: Creating an Service Definition File and Overwritting Existing Feature Service on ArcGIS Online
# Description: This script does the following:
# (1) Sets up the variables
# (2) Creates an SD File
# (3) Overwrites Existing Feature Service
#
# Date: 9/12/2017
#
# ---------------------------------------------------------------------------
import arcpy
import os, sys
from arcgis.gis import GIS
# Set the date.
Date = time.strftime("%m-%d-%Y", time.localtime())
# Set the time.
Time = time.strftime("%I:%M:%S %p", time.localtime())
print "Process started at " + str(Date) + " " + str(Time) + "." + "\n"
# ---------------- Setup the log file -------------------
LogFile = file('J:\\ENGSYS\\GIS_Testing\\ArcGISOnline_PublishingSrvc\\Logs\\RepublishingMapPortalService-' + Date + '.txt', 'w') #Creates a log file with todays date.
output = open('J:\\ENGSYS\\GIS_Testing\\ArcGISOnline_PublishingSrvc\\Logs\\RepublishingMapPortalService-' + Date + '.txt', 'w') #Path to log file.
output.write(str("Process started at " + str(Date) + " " + str(Time) + "." + "\n")) # Write the start time to the log file.
print " -------------------- Creating SD File -----------------------------"
### Start setting variables
# Set the path to the project
prjPath = r"J:\ENGSYS\GIS_Testing\ArcGISOnline_PublishingSrvc\TestScript.aprx"
# Update the following variables to match:
# Feature service/SD name in arcgis.com, user/password of the owner account
sd_fs_name = "XXXXX"
portal = "XXXXX" # Can also reference a local portal
user = "XXXXX"
password = "XXXX"
# Set sharing options
shrOrg = True
shrEveryone = False
shrGroups = ""
### End setting variables
# Local paths to create temporary content
relPath = sys.path[0]
sddraft = os.path.join(relPath, "WebUpdate.sddraft")
sd = os.path.join(relPath, "WebUpdate.sd")
# Create a new SDDraft and stage to SD
print("Creating SD file")
arcpy.env.overwriteOutput = True
prj = arcpy.mp.ArcGISProject(prjPath)
mp = prj.listMaps()[0]
arcpy.mp.CreateWebLayerSDDraft(mp, sddraft, sd_fs_name, 'MY_HOSTED_SERVICES', 'FEATURE_ACCESS','', True, True)
arcpy.StageService_server(sddraft, sd)
print("Connecting to {}".format(portal))
gis = GIS(portal, user, password)
# Find the SD, update it, publish /w overwrite and set sharing and metadata
print("Search for original SD on portal...")
sdItem = gis.content.search("{} AND owner:{}".format(sd_fs_name, user), item_type="Service Definition")[0]
print("Found SD: {}, ID: {} \n Uploading and overwriting...".format(sdItem.title, sdItem.id))
sdItem.update(data=sd)
print("Overwriting existing feature service...")
fs = sdItem.publish(overwrite=True)
if shrOrg or shrEveryone or shrGroups:
print("Setting sharing options...")
fs.share(org=shrOrg, everyone=shrEveryone, groups=shrGroups)
print("Finished updating: {} - ID: {}".format(fs.title, fs.id))
# ---------------- Output the log file -------------------
# Sets the Date & Time since the script started.
Date = time.strftime("%m-%d-%Y", time.localtime())# Set the date.
Time = time.strftime("%I:%M:%S %p", time.localtime()) # Set the time.
output.write(str("Process completed at " + str(Date) + " " + str(Time) + "." + "\n")) # Write the start time to the log file.
output.close() # Closes the log file.
print "Process completed at " + str(Date) + " " + str(Time) + "."
Solved! Go to Solution.
you have to use the python version installed in the anaconda distribution for pro ( see an example here using Spyder )
you might also want to format your code to rule out other errors
you have to use the python version installed in the anaconda distribution for pro ( see an example here using Spyder )
you might also want to format your code to rule out other errors