<?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: Matplotlib Import fails after successive run of custom tool in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/matplotlib-import-fails-after-successive-run-of/m-p/638110#M49725</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I can't explain your situation, but I will point out that it is by far more common to see the following, so I&amp;nbsp;suggest sticking to that for compatibility:&lt;/P&gt;&lt;PRE style="color: #333333; background-color: #f8f8f8; border: 1px solid #cccccc; padding: 1em;"&gt;&lt;SPAN class="" style="color: #007020; font-weight: bold;"&gt;import&lt;/SPAN&gt; &lt;SPAN class="" style="color: #0e84b5; font-weight: bold;"&gt;matplotlib.pyplot&lt;/SPAN&gt; &lt;SPAN class="" style="color: #007020; font-weight: bold;"&gt;as&lt;/SPAN&gt; &lt;SPAN class="" style="color: #0e84b5; font-weight: bold;"&gt;plt&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Aug 2018 18:19:35 GMT</pubDate>
    <dc:creator>DarrenWiens2</dc:creator>
    <dc:date>2018-08-16T18:19:35Z</dc:date>
    <item>
      <title>Matplotlib Import fails after successive run of custom tool</title>
      <link>https://community.esri.com/t5/python-questions/matplotlib-import-fails-after-successive-run-of/m-p/638109#M49724</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey all - I have a custom toolbox that imports Matplotlib and numpy to do some charting.&amp;nbsp; The tool will run perfect upon opening and on an initial run.&amp;nbsp; Each successive run in an open ArcMap session gives me the error: import matplotlib as plt KeyError: u'PolyCollection'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas or help is appreciated!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Aug 2018 15:33:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/matplotlib-import-fails-after-successive-run-of/m-p/638109#M49724</guid>
      <dc:creator>JoshStreufert</dc:creator>
      <dc:date>2018-08-16T15:33:31Z</dc:date>
    </item>
    <item>
      <title>Re: Matplotlib Import fails after successive run of custom tool</title>
      <link>https://community.esri.com/t5/python-questions/matplotlib-import-fails-after-successive-run-of/m-p/638110#M49725</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I can't explain your situation, but I will point out that it is by far more common to see the following, so I&amp;nbsp;suggest sticking to that for compatibility:&lt;/P&gt;&lt;PRE style="color: #333333; background-color: #f8f8f8; border: 1px solid #cccccc; padding: 1em;"&gt;&lt;SPAN class="" style="color: #007020; font-weight: bold;"&gt;import&lt;/SPAN&gt; &lt;SPAN class="" style="color: #0e84b5; font-weight: bold;"&gt;matplotlib.pyplot&lt;/SPAN&gt; &lt;SPAN class="" style="color: #007020; font-weight: bold;"&gt;as&lt;/SPAN&gt; &lt;SPAN class="" style="color: #0e84b5; font-weight: bold;"&gt;plt&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Aug 2018 18:19:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/matplotlib-import-fails-after-successive-run-of/m-p/638110#M49725</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2018-08-16T18:19:35Z</dc:date>
    </item>
    <item>
      <title>Re: Matplotlib Import fails after successive run of custom tool</title>
      <link>https://community.esri.com/t5/python-questions/matplotlib-import-fails-after-successive-run-of/m-p/638111#M49726</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Darren - I did have that at the top of my script.&amp;nbsp; I'm not entirely sure how to proceed without abandoning the matplotlib library.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Aug 2018 21:09:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/matplotlib-import-fails-after-successive-run-of/m-p/638111#M49726</guid>
      <dc:creator>JoshStreufert</dc:creator>
      <dc:date>2018-08-16T21:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: Matplotlib Import fails after successive run of custom tool</title>
      <link>https://community.esri.com/t5/python-questions/matplotlib-import-fails-after-successive-run-of/m-p/638112#M49727</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I might be barking up the wrong tree, but can you confirm you don't have both of these in your script?&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN class="" style="color: #007020; border: 0px; font-weight: bold; font-size: 14px;"&gt;import&lt;/SPAN&gt; &lt;SPAN class="" style="color: #0e84b5; border: 0px; font-weight: bold; font-size: 14px;"&gt;matplotlib.pyplot&lt;/SPAN&gt; &lt;SPAN class="" style="color: #007020; border: 0px; font-weight: bold; font-size: 14px;"&gt;as&lt;/SPAN&gt; &lt;SPAN class="" style="color: #0e84b5; border: 0px; font-weight: bold; font-size: 14px;"&gt;plt
&lt;SPAN class="" style="color: #007020; border: 0px; font-weight: bold;"&gt;import&lt;/SPAN&gt; &lt;SPAN class="" style="border: 0px; font-weight: bold;"&gt;matplotlib&lt;/SPAN&gt; &lt;SPAN class="" style="color: #007020; border: 0px; font-weight: bold;"&gt;as&lt;/SPAN&gt; &lt;SPAN class="" style="border: 0px; font-weight: bold;"&gt;plt&lt;/SPAN&gt;
&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;Perhaps more usefully, can you post the script you do have?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:07:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/matplotlib-import-fails-after-successive-run-of/m-p/638112#M49727</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-12T03:07:50Z</dc:date>
    </item>
    <item>
      <title>Re: Matplotlib Import fails after successive run of custom tool</title>
      <link>https://community.esri.com/t5/python-questions/matplotlib-import-fails-after-successive-run-of/m-p/638113#M49728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here are my import statements...&lt;/P&gt;&lt;P&gt;Like I said, runs fine the first time but subsequent times python throws an error like it cant load the library.&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; arcpy
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; os
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; datetime
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; exceptions&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; sys&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; traceback
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; matplotlib&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;pyplot &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; plt
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; numpy &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; np
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; math‍‍‍‍‍‍‍‍&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>Sun, 12 Dec 2021 03:07:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/matplotlib-import-fails-after-successive-run-of/m-p/638113#M49728</guid>
      <dc:creator>JoshStreufert</dc:creator>
      <dc:date>2021-12-12T03:07:53Z</dc:date>
    </item>
    <item>
      <title>Re: Matplotlib Import fails after successive run of custom tool</title>
      <link>https://community.esri.com/t5/python-questions/matplotlib-import-fails-after-successive-run-of/m-p/638114#M49729</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You might want to have a look at the variables you are using in your script... one may be overwriting a previously established namespace.&amp;nbsp; Modules are only reloaded if needed and if the namespace isn't claimed. &amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't know what version of python you are using but check for 'reload' in python 2 and the importlib reload module in python 3.&amp;nbsp; If the namespace isn't the problem, then reload the modules at the end of the script.&lt;/P&gt;&lt;P&gt;Also, import numpy before matplotlib because matplotlib doesn't import the whole numpy module and you want numpy's namespace to be claimed before anything else tries to claim it&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Aug 2018 22:03:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/matplotlib-import-fails-after-successive-run-of/m-p/638114#M49729</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-08-16T22:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: Matplotlib Import fails after successive run of custom tool</title>
      <link>https://community.esri.com/t5/python-questions/matplotlib-import-fails-after-successive-run-of/m-p/638115#M49730</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I&amp;nbsp;came across this&amp;nbsp;problem writing a custom tool for ArcGIS 10.6 and&amp;nbsp;distilled&amp;nbsp;it to the two lines below.&lt;/P&gt;&lt;P&gt;&lt;EM&gt;import matplotlib.pyplot as plt&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;plt.figure()&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When run from ArcMap, this would succeed the&amp;nbsp;first time then error on subsequent attempts to import the module...&lt;/P&gt;&lt;P style="margin-left: 7.5pt;"&gt;&lt;SPAN style="font-size: 10.0pt; color: #d70019;"&gt;&amp;nbsp; File "C:\Python27\ArcGIS10.6\lib\site-packages\matplotlib\quiver.py", line 171, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-left: 7.5pt;"&gt;&lt;SPAN style="font-size: 10.0pt; color: #d70019;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; """ % docstring.interpd.params&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-left: 7.5pt;"&gt;&lt;SPAN style="font-size: 10.0pt; color: #d70019;"&gt;KeyError: u'PolyCollection'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ended up solving by repairing&amp;nbsp;matplotlib using the ArcGIS Setup wizard. Not sure what may have been the cause.&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="432857" alt="" class="image-1 jive-image" height="318" src="https://community.esri.com/legacyfs/online/432857_repair.PNG" width="424" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jan 2019 17:29:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/matplotlib-import-fails-after-successive-run-of/m-p/638115#M49730</guid>
      <dc:creator>SilasFrantz</dc:creator>
      <dc:date>2019-01-09T17:29:37Z</dc:date>
    </item>
  </channel>
</rss>

