I was working with Python in IDLE and PyScripter but for some reason can't seem to get the code to work in either. The code only works in ArcMap. I am probably missing something simple but can't seem to place my finger on it. If you can help please let me know. I know this is simple code, but I want to run this in windows task scheduler. I really don't want to create a model, run it, then export it as a python script. I though it would be easier to just create a python script from scratch, perhaps not.
arcpy.env.overwriteOutput = True
arcpy.env.workspace = "O:\\Data\\GIS\\Dept\\Fire\\hydrants"
mxd = os.path.join(arcpy.env.workspace,"FireHydrant_Utility.mxd")
mpk = os.path.join(arcpy.env.workspace,"FireHydrant_Package.mpk")
print "Map Package Complete"
Solved! Go to Solution.
Try the same test but run your script using the .bat file located here:
Does this complete successfully? Do you get the 999999 Error when using PyScripter or another method to run your standalone scripts? Try using the 32-bit version of PyScripter.
Do you get an error outside ArcMap, perhaps something like "no module named arcpy"? Along those lines, do you have multiple python installations on your computer, and are your IDEs pointing to the correct one?
When I print the system path it appears as if all paths point to a 10.2 version or Python27 version. I do have a Python26 installed on my computer from the 10.0 version of Arc.
'C:\\Program Files (x86)\\ArcGIS\\Desktop10.2\\bin64',
'C:\\Program Files (x86)\\ArcGIS\\Desktop10.2\\arcpy',
'C:\\Program Files (x86)\\ArcGIS\\Desktop10.2\\ArcToolbox\\Scripts',
Go into your IDE outside of python (ie PyScripter or PythonWin),
Import the sys module and get the python path...ie it should look something like this
[... 'C:\\Python27\\ArcGIS10.2\\DLLs', 'C:\\Python27\\ArcGIS10.2\\lib', 'C:\\Python27\\ArcGIS10.2\\lib\\plat-win', 'C:\\Python27\\ArcGIS10.2\\lib\\lib-tk', 'C:\\Python27\\ArcGIS10.2\\Lib\\site-packages\\pythonwin', 'C:\\Python27\\ArcGIS10.2', 'C:\\Python27\\ArcGIS10.2\\lib\\site-packages', 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.2\\bin', 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.2\\arcpy', 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.2\\ArcToolbox\\Scripts', 'C:\\Python27\\ArcGIS10.2\\lib\\site-packages\\win32', 'C:\\Python27\\ArcGIS10.2\\lib\\site-packages\\win32\\lib'...]
The key path is 'C:\\Python27\\ArcGIS10.2.... or whatever your version number is. And if you are using 10.3...it will be different like Python34(?)
We do have ArcGIS Desktop and ArcGIS Server installed on the web box. However, this particular script is running on my local machine creating a map package where I only have ArcGIS Desktop installed.