<?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: Python: Create Python Module from existing Python Toolbox in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508119#M39921</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Luke&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I created the following directory and placed my GeoHMSTools.py module within the following directory. When I try to import GeoHMSTools module within Python it says it cant find the following module.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; import arcpy
&amp;gt;&amp;gt;&amp;gt; import GeoHMSTools
Runtime error 
Traceback (most recent call last):
&amp;nbsp; File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;
ImportError: No module named GeoHMSTools
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried adding the path of the following directory to the environment settings, but it had no effect.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 22:16:07 GMT</pubDate>
    <dc:creator>PeterWilson</dc:creator>
    <dc:date>2021-12-11T22:16:07Z</dc:date>
    <item>
      <title>Python: Create Python Module from existing Python Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508111#M39913</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I posted the following article: &lt;A href="https://community.esri.com/thread/171548" target="_blank"&gt;HEC-GeoHMS: Importing HEC-GeoHMS Toolbox &lt;/A&gt;&amp;nbsp; asking for assistance in how to import HEC-GeoHMS into python. I received an email a while back from Christine Dartiguenave from the Arc Hydro Team, suggesting to run the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import arcpy.toolbox_code
arcpy.toolbox_code.generate_toolbox_module (r'C:\Program Files (x86)\ArcGIS\Desktop10.2\ArcToolbox\Toolboxes\GeoHMS Tools.tbx', r'C:\Projects\GeoHMSTools.py',False, False,True,'geohms')&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I try to import GeoHMSTools within Python I receive the following error message:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import GeoHMSTools
Runtime error 
Traceback (most recent call last):
&amp;nbsp; File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;
ImportError: No module named GeoHMSTools&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not sure if I'm meant to copy the python script that is created under C:\Projects i.e. GeoHMSTools.py into another directory, before trying to import it into Python.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:15:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508111#M39913</guid>
      <dc:creator>PeterWilson</dc:creator>
      <dc:date>2021-12-11T22:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: Python: Create Python Module from existing Python Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508112#M39914</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Python doesn't know where to find &lt;SPAN class="string"&gt;C:\Projects\GeoHMSTools.py&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="string"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="string"&gt;A few ways to tell python where to look:&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;SPAN class="string"&gt;Save your python script to &lt;SPAN class="string"&gt;C:\Projects (python will look in the same directory as your script for any modules); &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class="string"&gt;&lt;SPAN class="string"&gt;Append &lt;SPAN class="string"&gt;C:\Projects to your sys.path;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN class="string"&gt;&lt;SPAN class="string"&gt;&lt;SPAN class="string"&gt;Install the module to your USER SITE directory (%AppData%\Python\Python27\site-packages)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Feb 2016 22:03:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508112#M39914</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2016-02-01T22:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: Python: Create Python Module from existing Python Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508113#M39915</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Luke has made an important point should you wish to distribute the toolset.&amp;nbsp; His first point about about where python "look" when it needs to find stuff.&amp;nbsp; You can examine this aspect by placing two scripts in the same folder and having one script import functions etc from the other.&amp;nbsp; You can zip and ship everything in a folder and python will have no issues of doing the relative imports&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Feb 2016 22:11:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508113#M39915</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-02-01T22:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: Python: Create Python Module from existing Python Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508114#M39916</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Luke&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the following. I copied the GeoHMSTools.py under the following directory:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;C:\Program Files (x86)\ArcGIS\Desktop10.2\ArcToolbox\Scripts&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was then able to import GeoHMSTools within Python, but when I try to run any of the tools Python crashes and I recieve the following error message:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;GeoHMSTools.CentroidalLongestFlowpath(r'E:\Python\Temp\Model02\Model02.gdb\Layers\Subwatershed',r'E:\Python\Temp\Model02\Model02.gdb\Layers\Centroid' , r'E:\Python\Temp\Model02\Model02.gdb\Layers\LongestFlowPath_2D', r'E:\Python\Temp\Model02\Model02.gdb\Layers\CentroidalLongestFlowPath6')
Runtime error&amp;nbsp; Traceback (most recent call last):&amp;nbsp;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;&amp;nbsp;&amp;nbsp; File "c:\program files (x86)\arcgis\desktop10.2\ArcToolbox\Toolboxes\GeoHMSTools.py", line 113, in CentroidalLongestFlowpath ExecuteError: System.Runtime.InteropServices.COMException (0x8002000A): Out of present range. (Exception from HRESULT: 0x8002000A (DISP_E_OVERFLOW))&amp;nbsp;&amp;nbsp;&amp;nbsp; at ESRI.ArcGIS.esriSystem.IStepProgressor.set_StepValue(Int32 Step)&amp;nbsp;&amp;nbsp;&amp;nbsp; at ESRI.APWR.HECGeoHMS10.GPCentroidalLongestFlowPath.CentroidalLongestFlowpathWk(ApLayers apLayers, Int32 debug, ITrackCancel&amp;amp; trackcancel, IGPMessages&amp;amp; messages, String&amp;amp; exMessage) Failed to execute (CentroidalLongestFlowpath).&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:16:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508114#M39916</guid>
      <dc:creator>PeterWilson</dc:creator>
      <dc:date>2021-12-11T22:16:02Z</dc:date>
    </item>
    <item>
      <title>Re: Python: Create Python Module from existing Python Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508115#M39917</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wouldn't put your script in the ArcGIS directory. You're better off moving it to &lt;SPAN class="string"&gt;&lt;SPAN class="string"&gt;&lt;SPAN class="string"&gt;%AppData%\Python\Python27\site-packages.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="string"&gt;&lt;SPAN class="string"&gt;&lt;SPAN class="string"&gt;I think you should focus on your earlier &lt;A _jive_internal="true" href="https://community.esri.com/thread/171548"&gt;question&lt;/A&gt; and try and get HEC-GeoHMS running from its toolbox. Instead of exporting a model, run the tool from the GUI, open the results window, &lt;SPAN class="string"&gt;&lt;SPAN class="string"&gt;&lt;SPAN class="string"&gt;right-click&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt; the result from the tool you just ran and select "copy as python snippet"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Feb 2016 08:36:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508115#M39917</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2016-02-02T08:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: Python: Create Python Module from existing Python Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508116#M39918</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Luke&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for getting back to me. I don't seem to have the following directory under C Drive: &lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;%AppData%\Python\Python27\site-packages.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;I've run the script tool within ArcMap and ArcCatalog with success. I tried Copy As Python Snippet and ran it within the ArcMap Python Interpreter:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import GeoHMSTools
arcpy.CentroidalLongestFlowpath_geohms(in_subbasin_features="E:/Python/Temp/Model02/Model02.gdb/Layers/Subwatershed",in_centroid_features="E:/Python/Temp/Model02/Model02.gdb/Layers/Centroid",in_longestflowpath_features="E:/Python/Temp/Model02/Model02.gdb/Layers/LongestFlowPath_2D",out_centroidallongestflowpath_raster="E:/Python/Temp/Model02/Model02.gdb/Layers/CentroidalLongestFlowPath1")
Runtime error 
Traceback (most recent call last):
&amp;nbsp; File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;
AttributeError: 'module' object has no attribute 'CentroidalLongestFlowpath_geohms'&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As you can see the syntax&amp;nbsp; is different for some reason or other, than when I call the tool from within the ArcMap Python Interpreter:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import GeoHMSTools
GeoHMSTools.CentroidalLongestFlowpath(r'E:\Python\Temp\Model02\Model02.gdb\Layers\Subwatershed', r'E:\Python\Temp\Model02\Model02.gdb\Layers\Centroid', r'E:\Python\Temp\Model02\Model02.gdb\Layers\LongestFlowPath_2D', r'E:\Python\Temp\Model02\Model02.gdb\Layers\CentroidalLongestFlowPath2')
Runtime error&amp;nbsp; Traceback (most recent call last):&amp;nbsp;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;&amp;nbsp;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.2\ArcToolbox\Scripts\GeoHMSTools.py", line 125, in CentroidalLongestFlowpath&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise e ExecuteError: System.Runtime.InteropServices.COMException (0x8002000A): Out of present range. (Exception from HRESULT: 0x8002000A (DISP_E_OVERFLOW))&amp;nbsp;&amp;nbsp;&amp;nbsp; at ESRI.ArcGIS.esriSystem.IStepProgressor.set_StepValue(Int32 Step)&amp;nbsp;&amp;nbsp;&amp;nbsp; at ESRI.APWR.HECGeoHMS10.GPCentroidalLongestFlowPath.CentroidalLongestFlowpathWk(ApLayers apLayers, Int32 debug, ITrackCancel&amp;amp; trackcancel, IGPMessages&amp;amp; messages, String&amp;amp; exMessage) Failed to execute (CentroidalLongestFlowpath).&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have found that although the GeoHMSTools.CentroidalLongestFlowpath() failed, if I open the results window and open the failed script and rerun it, it completes successfully.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:16:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508116#M39918</guid>
      <dc:creator>PeterWilson</dc:creator>
      <dc:date>2021-12-11T22:16:04Z</dc:date>
    </item>
    <item>
      <title>Re: Python: Create Python Module from existing Python Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508117#M39919</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Peter Wilson wrote:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't seem to have the following directory under C Drive: &lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;%AppData%\Python\Python27\site-packages.&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;You can create it and python will use it automatically (&lt;A href="https://www.python.org/dev/peps/pep-0370/"&gt;PEP370&lt;/A&gt;). I &lt;EM&gt;strongly&lt;/EM&gt; recommend against putting stuff in the ArcGIS folder.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Feb 2016 21:54:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508117#M39919</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2016-02-02T21:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: Python: Create Python Module from existing Python Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508118#M39920</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nice PEP... I missed that one. Not finding anything for iOS since I use Pythonista for pure python,numpy,scipy stuff.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Feb 2016 00:49:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508118#M39920</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-02-03T00:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: Python: Create Python Module from existing Python Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508119#M39921</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Luke&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I created the following directory and placed my GeoHMSTools.py module within the following directory. When I try to import GeoHMSTools module within Python it says it cant find the following module.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; import arcpy
&amp;gt;&amp;gt;&amp;gt; import GeoHMSTools
Runtime error 
Traceback (most recent call last):
&amp;nbsp; File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;
ImportError: No module named GeoHMSTools
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried adding the path of the following directory to the environment settings, but it had no effect.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:16:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508119#M39921</guid>
      <dc:creator>PeterWilson</dc:creator>
      <dc:date>2021-12-11T22:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: Python: Create Python Module from existing Python Toolbox</title>
      <link>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508120#M39922</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Luke and Dan&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm going to close the following as i feel the error messages that I'm receiving while trying to call Geo-HMS tools within Python are due to HEC-GeoHMS and not the Python Module that I've created. I've did a bit of research and found that ESRI has placed the ArcHydroTools.py module under the following directory:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;C:\Program Files\ESRI\WaterUtils\ArcHydro\Bin&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;They generated a path file under the following directory that points to the module:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;C:\Python27\ArcGISx6410.2\Lib\site-packages&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I've replicated the same for HEC-GeoHMS and I'm able to call GeoHMSTools within Python. The Centroidal Longest Flowpath tool still fails though and crashes Python. I'm going to open a new thread to see if anyone has gotten Centroidal Longest Flowpath to run from within Python. Thanks for all your assisstance.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 03 Feb 2016 05:47:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-create-python-module-from-existing-python/m-p/508120#M39922</guid>
      <dc:creator>PeterWilson</dc:creator>
      <dc:date>2016-02-03T05:47:40Z</dc:date>
    </item>
  </channel>
</rss>

