Python only works in ArcMap

4908
19
Jump to solution
02-25-2015 02:41 PM
HeathAnderson
Occasional Contributor

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

1 Solution

Accepted Solutions
AdamMarinelli
Occasional Contributor

Try the same test but run your script using the .bat file located here:

  • "C:\Python27\ArcGISx6410.2\Lib\idlelib\idle.bat"

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.

View solution in original post

Reply
0 Kudos
19 Replies
DarrenWiens2
MVP Honored Contributor

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?

Reply
0 Kudos
HeathAnderson
Occasional Contributor

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']

Reply
0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

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(?)

AdamMarinelli
Occasional Contributor

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

AsrujitSengupta
Regular Contributor III

Is ArcGIS Desktop and ArcGIS Server installed on the same machine?

If yes, are you using the 32-bit Python for that script?

Reply
0 Kudos
HeathAnderson
Occasional Contributor

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.

Reply
0 Kudos
AsrujitSengupta
Regular Contributor III

Can you please post the error message.

Reply
0 Kudos
DanPatterson_Retired
MVP Esteemed Contributor

'C:\\Python27\\ArcGISx6410.2    suggests that it isn't a conventional install, how was arcmap installed?

Reply
0 Kudos
HeathAnderson
Occasional Contributor

No just Desktop 10.2

Reply
0 Kudos