<?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 ArcPy in Created Python Modules? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-in-created-python-modules/m-p/288150#M22293</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to use the arcpy module in functions that are within custom Python modules that I've created, but I keep getting this error:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;STRONG&gt;NameError: global name 'arcpy' is not defined&lt;/STRONG&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;How do I fix this? These modules will be used within ArcGIS, where ArcPy is already loaded.&lt;/P&gt;&lt;P&gt;I've tried with and without "&lt;STRONG&gt;import arcpy&lt;/STRONG&gt;".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example:&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;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;refresher&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="string token"&gt;''' Refreshes map and TOC '''&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;RefreshActiveView&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;RefreshTOC&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Refreshed map and TOC.'&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 13:55:23 GMT</pubDate>
    <dc:creator>MarcusSanders2</dc:creator>
    <dc:date>2021-12-11T13:55:23Z</dc:date>
    <item>
      <title>ArcPy in Created Python Modules?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-in-created-python-modules/m-p/288150#M22293</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to use the arcpy module in functions that are within custom Python modules that I've created, but I keep getting this error:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;STRONG&gt;NameError: global name 'arcpy' is not defined&lt;/STRONG&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;How do I fix this? These modules will be used within ArcGIS, where ArcPy is already loaded.&lt;/P&gt;&lt;P&gt;I've tried with and without "&lt;STRONG&gt;import arcpy&lt;/STRONG&gt;".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example:&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;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;refresher&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="string token"&gt;''' Refreshes map and TOC '''&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;RefreshActiveView&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;RefreshTOC&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Refreshed map and TOC.'&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 13:55:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-in-created-python-modules/m-p/288150#M22293</guid>
      <dc:creator>MarcusSanders2</dc:creator>
      <dc:date>2021-12-11T13:55:23Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy in Created Python Modules?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-in-created-python-modules/m-p/288151#M22294</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So you are saying that you can use the builtin python IDE and you have not problem with or without importing arcpy.&lt;/P&gt;&lt;P&gt;But you say it fails in your 'outside' python IDE, whether you import arcpy or not.&lt;/P&gt;&lt;P&gt;If the latter is the case, then either your installation is incorrect, your IDE knows nothing about the location of the arcpy module.&lt;/P&gt;&lt;P&gt;You also failed to indicate whether this is for ArcMap or ArcGIS PRO... ArcGIS is a flakey term in terms of identifying what you are working with, since there is the 'arcgis' module and myriad of things with that moniker.&lt;/P&gt;&lt;P&gt;You did flag python 2, so presumably you are working with arcmap, therefore your installation path for Python and Arcpy is in the&amp;nbsp;&lt;/P&gt;&lt;P&gt;C:\Pythonx.x\ArcGIS10.X\ .... folder where the x's are version numbers.&lt;/P&gt;&lt;P&gt;If you have multiple instances of python installed outside a conda distribution, uninstall them&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Provide more details if none of this applies.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Nov 2017 14:44:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-in-created-python-modules/m-p/288151#M22294</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-11-15T14:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy in Created Python Modules?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-in-created-python-modules/m-p/288152#M22295</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No, I can't use this within the builtin python IDE in ArcGIS. I'd assume that arcpy was already loaded and ready for use after opening the program, but that's not the case when I remove the "import arcpy" line. It doesn't work whether I import arcpy or not within my module.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, I'm working in ArcMap 10.5 (py2), and no changes to conda.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Nov 2017 14:54:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-in-created-python-modules/m-p/288152#M22295</guid>
      <dc:creator>MarcusSanders2</dc:creator>
      <dc:date>2017-11-15T14:54:41Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy in Created Python Modules?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-in-created-python-modules/m-p/288153#M22296</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you can't import arcpy anywhere, then your installation is corrupt or somehow being misdirected.&amp;nbsp; Big chance to uninstall python (from all locations) and do a 'Repair' from the install/remove in windows.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Nov 2017 15:06:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-in-created-python-modules/m-p/288153#M22296</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-11-15T15:06:28Z</dc:date>
    </item>
    <item>
      <title>Re: ArcPy in Created Python Modules?</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-in-created-python-modules/m-p/288154#M22297</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;ArcPy can be imported. I just realized my issue came from not restarting ArcMap after changing my script; even after reimporting my module (without restarting), it doesn't see the changes until I restart.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It works now, and looks like &lt;STRONG&gt;import arcpy&lt;/STRONG&gt; is required.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Solution&lt;/STRONG&gt;: make sure &lt;STRONG&gt;import arcpy&lt;/STRONG&gt; is in the module, and restart ArcMap after any changes to the .py file&lt;/P&gt;&lt;P&gt;&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;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;refresher&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="string token"&gt;''' Refreshes map and TOC '''&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;RefreshActiveView&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;RefreshTOC&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Refreshed map and TOC.'&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 13:55:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-in-created-python-modules/m-p/288154#M22297</guid>
      <dc:creator>MarcusSanders2</dc:creator>
      <dc:date>2021-12-11T13:55:25Z</dc:date>
    </item>
  </channel>
</rss>

