I have recently upgraded to ArcGIS 10.3 and all my script tools are not working. For some reason, within any ArcGIS process, the built-in sys module does not have the argv attribute. It works as expected in stand-alone. This affects me because I use sys.argv in virtually all the script tools I have developed for my organization (70+) to pass in arguments.
For example, if I have a function like this:
def function(arg1, arg2, arg3): pass
It is easier to call the function and pass in parameters from a script tool like this:
function(*sys.argv[1:])
rather than:
param1 = arcpy.GetParameterAsText(0) param2 = arcpy.GetParameterAsText(1) param3 = arcpy.GetParameterAsText(2) function(param1, param2, param3)
However, after the upgrade, ONLY in any ArcGIS process the sys module is lacking the argv attribute. See pictures below:
fails in ArcGIS Python Window
and works as expected in regular IDLE shell
Is there something different about how ArcGIS is accessing Python in version 10.3?
Solved! Go to Solution.
Weird, sys works normally on my 10.3 system.
I'll copy this thread to our Python people but as you're dead in the water you might want to open a support call.
Regards
Yes, this is what I used to use before I switched to sys.argv[1:]. I uninstalled ArcGIS 10.3 and re-installed and it seemed to fix the issue. Something must have gotten corrupted when I did the original install.
Caleb
What do you get in a Python Window with this statement?
hasattr(sys,'argv')
Regards
It says False. It also does not show up as it should if I use dir(sys). It is simply gone.
Weird, sys works normally on my 10.3 system.
I'll copy this thread to our Python people but as you're dead in the water you might want to open a support call.
Regards
Yes, I'm talking to support right now. I logged onto one of our new servers with 10.3, and I could not reproduce this issue. Must be an error with my install. Thank you, Bruce.
Hi Caleb,
Anything else missing on sys? What does dir(sys) return?
On mine, I see
>>> dir(sys) ['__displayhook__', '__doc__', '__egginsert', '__excepthook__', '__name__', '__package__', '__plen', '__stderr__', '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames', '_getframe', '_mercurial', 'api_version', 'argv', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dllhandle', 'dont_write_bytecode', 'exc_clear', 'exc_info', 'exc_type', 'excepthook', 'exec_prefix', 'executable', 'exit', 'exitfunc', 'flags', 'float_info', 'float_repr_style', 'getcheckinterval', 'getdefaultencoding', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'gettrace', 'getwindowsversion', 'hexversion', 'long_info', 'maxint', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'py3kwarning', 'setcheckinterval', 'setprofile', 'setrecursionlimit', 'settrace', 'stderr', 'stdin', 'stdout', 'subversion', 'version', 'version_info', 'warnoptions', 'winver']
-Dave
If you need to evade this with minimum edits, could use an approach like below to mimic what sys.argv gives you.
argv = tuple(arcpy.GetParameterAsText(i) for i in range(arcpy.GetArgumentCount()))
-Dave
This is the method I use, in the hope that GetParameterAsText will play nicer (cleaner) with the GP architecture than going out to sys.argv. Maybe it doesn't matter.
Yes, this is what I used to use before I switched to sys.argv[1:]. I uninstalled ArcGIS 10.3 and re-installed and it seemed to fix the issue. Something must have gotten corrupted when I did the original install.
Hi Caleb
I came across this a few weeks ago with another site here in Auckland. It seems like a sort of custom install was rolled out to the business and python was not installed correctly. It happens a lot when IT roll out GIS software across the organisation.
Also, can you check if Python 2.7 is installed under ArcGIS ?
Are there any other copies of Python 2.7 still hanging around the machine?
Perhaps the Python windows environmental variables need still to be configured,
I have always done the ESRI standard installation and it has always worked for me.
Susan