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.
import arcpy import os 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") arcpy.PackageMap_management(mxd,mpk,"CONVERT","CONVERT_ARCSDE","#","ALL","DESKTOP","NOT_REFERENCED","ALL","#","#","#") print "Map Package Complete"
Cheers,
Heath
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\\PyScripter\\Lib\\rpyc.zip',
'C:\\Windows\\system32\\python27.zip',
'C:\\Python27\\ArcGISx6410.2\\DLLs',
'C:\\Python27\\ArcGISx6410.2\\lib',
'C:\\Python27\\ArcGISx6410.2\\lib\\plat-win',
'C:\\Python27\\ArcGISx6410.2\\lib\\lib-tk',
'C:\\Python27\\ArcGISx6410.2',
'C:\\Python27\\ArcGISx6410.2\\lib\\site-packages',
'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',
'C:\\Python27\\ArcGISx6410.2\\lib\\site-packages\\win32',
'C:\\Python27\\ArcGISx6410.2\\lib\\site-packages\\win32\\lib',
'C:\\Python27\\ArcGISx6410.2\\lib\\site-packages\\Pythonwin']
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
import sys
>>> sys.path
[... '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(?)
Quick note: ArcGIS for Desktop 10.3 still uses Python 2.7.8 -- I think it is only ArcGIS Pro that has made the jump to Python 3.4
Is ArcGIS Desktop and ArcGIS Server installed on the same machine?
If yes, are you using the 32-bit Python for that script?
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.
Can you please post the error message.
'C:\\Python27\\ArcGISx6410.2 suggests that it isn't a conventional install, how was arcmap installed?
No just Desktop 10.2