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.
My question IS how can we know if Pyscripter and ArcMap can communicate to each other BUT what if I want just run like a debug first before the actully work in ArcMap ?
For example, you write the code and test it and shows it work and then you can run it either in Python Window or Pyscripter to get the results done ?
Try importing the product license before arcpy to run alone. For example
import arceditor
import arcpy
The code I test work just fine in ArcMap in the python command window but with i try and run it outside of ArcMap it fails. More specifically the arcpy.PackageMap_management fails and raises error 9999999. This is a general error of course. In thinking that I may have written the code incorrectly or assigned an invalid input I ran the Package Map tool in ArcMap and copied the python code from the geoprocessing results window, then pasted it into PyScripter, and still no luck.
I tried adding importing the arceditor as a module and that had no affect.
I believe that PyScripter can can see the arcpy module because it will callout available classes and methods as you type.
Hello Heath,
If your script is getting all the way down to line 10 and breaking on the Package Map tool...then your IDE is properly "importing arcpy" and this is likely not the issue.
Can you run a quick test: Create a blank new MXD, add one or two simple layers from a local File Geodatabase, edit the paths in your scripts, and re-run. See if you get the same error as before.
Also, your code looks good. I just ran in on my machine (although, using ArcGIS 10.3) with a different MXD and it completed successfully.
The script seems to be okay in ArcMap. The code also runs okay in Py.Win. I ran sys.path in both ArcMap and PyScripter. The returns were pointing to different folders in Python27. I think this maybe the problem but not sure, and if it is, I am not sure how to remedy the problem. I'll attach a screenshot. Any suggestions???
Did you install the 32-bit or 64-bit version of PyScripter? From your screenshot it looks like the 64-bit version. ArcMap is using the 32-bit version of its python install (C:\Python27\ArcGIS10.2) when background geoprocessing is turned off.
This GIS StackExchange question might help.
Also try this:
I was able to get the script to run in the idle.bat at
I do have the 64 bit pyscripter installed and am running the 64bit machine. I believe that i have installed background geoprocessing in ArcMap. Do i need to call background geoprocessing out in python? Not really sure what my next steps should be...
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.
I ended up installing PyScripter for 32-bit.