Here is the situation I am in. I am writing a geoprocessing service in python using Arcpy module, first thing I do is to import the arcpy module using "import arcpy" on desktop machine with PyCharm where ArcGIS Desktop 10.5 (v 10.5.0.6491) is installed.
It works perfectly fine most of the times but if there are no ArcMap desktop licenses to checkout, the first line of import statement fails with "RuntimeError: NotInitialized".
I know we can use arcpy.CheckProduct to check the availability of extensions and products but import arcpy module itself fails in the first place.
Could you please anyone suggest what is the best choice to handle such scenario to check whether we can import arcpy else return with appropriate message to exit gracefully.
Thanks in advance.