<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Failed to import ArcPy when there is no license in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/failed-to-import-arcpy-when-there-is-no-license/m-p/201751#M15514</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;several ways, but it depends on your script.&lt;/P&gt;&lt;P&gt;You could put in a&amp;nbsp; try, except block&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; sys
&lt;SPAN class="keyword token"&gt;try&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy
&lt;SPAN class="keyword token"&gt;except&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"no arcpy license"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;finally&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; sys&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;exit&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 10:01:43 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2021-12-11T10:01:43Z</dc:date>
    <item>
      <title>Failed to import ArcPy when there is no license</title>
      <link>https://community.esri.com/t5/python-questions/failed-to-import-arcpy-when-there-is-no-license/m-p/201750#M15513</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Prem&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 May 2018 09:10:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/failed-to-import-arcpy-when-there-is-no-license/m-p/201750#M15513</guid>
      <dc:creator>Prem_KumarThogiti</dc:creator>
      <dc:date>2018-05-28T09:10:45Z</dc:date>
    </item>
    <item>
      <title>Re: Failed to import ArcPy when there is no license</title>
      <link>https://community.esri.com/t5/python-questions/failed-to-import-arcpy-when-there-is-no-license/m-p/201751#M15514</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;several ways, but it depends on your script.&lt;/P&gt;&lt;P&gt;You could put in a&amp;nbsp; try, except block&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; sys
&lt;SPAN class="keyword token"&gt;try&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy
&lt;SPAN class="keyword token"&gt;except&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"no arcpy license"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;finally&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; sys&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;exit&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:01:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/failed-to-import-arcpy-when-there-is-no-license/m-p/201751#M15514</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T10:01:43Z</dc:date>
    </item>
    <item>
      <title>Re: Failed to import ArcPy when there is no license</title>
      <link>https://community.esri.com/t5/python-questions/failed-to-import-arcpy-when-there-is-no-license/m-p/201752#M15515</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If your objective is to create a geoprocessing service, you will not need to check for the license since it will be present in ArcGIS Server. Just make sure you have a license available the moment you run the script before publishing the GP service to the Server, which you will always have, since you will have to run it from inside Desktop in order to be able to publish the script as a service.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 May 2018 09:57:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/failed-to-import-arcpy-when-there-is-no-license/m-p/201752#M15515</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2018-05-28T09:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: Failed to import ArcPy when there is no license</title>
      <link>https://community.esri.com/t5/python-questions/failed-to-import-arcpy-when-there-is-no-license/m-p/201753#M15516</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I appreciate your time responding to my question. Thank you. That's exactly what I wrote and moving ahead but I thought there must be a pythonic way to check whether ArcMap license is available on the machine or not.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The other day I was trying this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import imp&lt;/P&gt;&lt;P&gt;info=imp.find_module('arcpy')&lt;/P&gt;&lt;P&gt;mod = imp.load_module('arcpy', *info)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Even at the line#3, I hit the same. Of course, line#2 at least tells me whether ArcMap is installed or not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, I can go ahead with the exception indicator. Thanks Dan.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 May 2018 10:14:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/failed-to-import-arcpy-when-there-is-no-license/m-p/201753#M15516</guid>
      <dc:creator>Prem_KumarThogiti</dc:creator>
      <dc:date>2018-05-28T10:14:55Z</dc:date>
    </item>
  </channel>
</rss>

