<?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: Errors when converting .py to .exe due to arcpy module in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/errors-when-converting-py-to-exe-due-to-arcpy/m-p/204757#M15753</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is there a reason you're compiling to an .exe? To obscure the code or because you're bundling third party modules? If you're just trying to obscure the code, you can have two files (in the same directory) like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;tool_implementation.py&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
def main():
&amp;nbsp;&amp;nbsp; &amp;lt;your geoprocessing script&amp;gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;tool_gp.py&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import tool_implementation
tool_implementation.main()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then set the path of the script tool to tool_gp.py in your toolbox, and run it once. Once tool_implementation.pyc exists, you can delete tool_implementation.py and your implementation will be obscured.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 10:08:56 GMT</pubDate>
    <dc:creator>JasonScheirer</dc:creator>
    <dc:date>2021-12-11T10:08:56Z</dc:date>
    <item>
      <title>Errors when converting .py to .exe due to arcpy module</title>
      <link>https://community.esri.com/t5/python-questions/errors-when-converting-py-to-exe-due-to-arcpy/m-p/204753#M15749</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to convert a python script to an exe using py2exe. When I do this several errors occur in the STDOUT. For example, I see the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The following modules appear to be missing&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;['_scproxy', 'arcobjects.Result', 'arcobjects._BaseArcObject', 'geoprocessing.env', 'geoprocessing.gp', 'mobile', 'production', 'sa.Raster']&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My python script is importing arcpy such as:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# ESRI package&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Although an exe is created, the executable crashes when it reaches the arcpy import.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Has anyone experienced this (Users or ESRI)?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The reason why I need to do this is because there are many libraries that do not exist on the local machines that will be running this program and it is easiest to 'compile' the program versus installing all the libraries that I require on each local machine.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for your help,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Feb 2011 21:37:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/errors-when-converting-py-to-exe-due-to-arcpy/m-p/204753#M15749</guid>
      <dc:creator>MichaelO_Donnell1</dc:creator>
      <dc:date>2011-02-25T21:37:09Z</dc:date>
    </item>
    <item>
      <title>Re: Errors when converting .py to .exe due to arcpy module</title>
      <link>https://community.esri.com/t5/python-questions/errors-when-converting-py-to-exe-due-to-arcpy/m-p/204754#M15750</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You will need to figure out another solution (using pip/virtualenv to build a local installation of Python and/or bundling all your extra libraries in a separate folder and adding it to sys.path &lt;/SPAN&gt;&lt;A href="http://docs.python.org/library/modulefinder.html"&gt;hint: modulefinder&lt;/A&gt;&lt;SPAN&gt;). If your py2exe bundle includes arcpy and/or arcgisscripting you can exclude them in the blacklist in your setup.py -- that should not only fix the majority of the problem but get you around potential license violations of redistributing Esri binaries.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Feb 2011 22:23:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/errors-when-converting-py-to-exe-due-to-arcpy/m-p/204754#M15750</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2011-02-25T22:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: Errors when converting .py to .exe due to arcpy module</title>
      <link>https://community.esri.com/t5/python-questions/errors-when-converting-py-to-exe-due-to-arcpy/m-p/204755#M15751</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Jason. I am using distributed computing for python applications and we have approx 200 licenses. To work around the problem I described, I run the python script on each machine and use sys.path.append(), which points to an NTFS where the libraries that I require exist (non-standard python libraries). Because each machine has a valid license and installation of Desktop and python, I can run the python script, access arcpy and with the sys.path.append(), I can access the other python libraries I require. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 06 Mar 2011 22:30:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/errors-when-converting-py-to-exe-due-to-arcpy/m-p/204755#M15751</guid>
      <dc:creator>MichaelO_Donnell1</dc:creator>
      <dc:date>2011-03-06T22:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: Errors when converting .py to .exe due to arcpy module</title>
      <link>https://community.esri.com/t5/python-questions/errors-when-converting-py-to-exe-due-to-arcpy/m-p/204756#M15752</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am also trying to convert a python script to an exe using py2exe. The python script is associated with an ArcToolBox, and it works fine as a python file but not as an exe.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have excluded arcgisscripting module from the setup.py: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;from distutils.core import setup&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import py2exe&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;opts = {"py2exe": {"includes":["doc_if_comunes"],&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; "excludes":['_ssl', "arcgisscripting",&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; 'pyreadline', 'difflib', 'doctest', 'locale',&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; 'optparse', 'pickle', 'calendar'], &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; "dist_dir":r"W:\0_FUENTES_PROGRAMAS\DOCUMENTACION_INCENDIOS\dist\DOCUMENTACION_INCENDIOS"}} &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;setup(windows=[os.getcwd() + 'PerimetrosAFrentes.py'],options=opts)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Path to arcgisscripting is set in PerimetroAFrentes.py:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import sys&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sys.path.append(r'C:\Archivos de programa\ArcGIS\Bin')&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import os&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import doc_if_comunes&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcgisscripting&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import string, tempfile&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create(9.3)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.SetProduct("ArcInfo")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def Principal():&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; gp.AddToolbox(doc_if_comunes.pathArcGIS() + r"ArcToolbox\Toolboxes\Data Management Tools.tbx")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; #lineas temporal&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; tempdir = tempfile.gettempdir()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; li_tmp = os.path.join(tempdir,"shp_lines.shp")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; if gp.Exists(li_tmp): gp.Delete(li_tmp)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; gp.AddWarning(str(gp.Exists(r'ACTUAL\LINEAS')))&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; desc = gp.Describe(r'ACTUAL\LINEAS')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; fc_li_a = desc.CatalogPath&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcgisscripting is properly imported as gp is created, shp_lines deleted and gp.Exists(r'ACTUAL\LINEAS') returns true (LINEAS is a feature layer in ArcMap). Nevertheless, the program breaks down in desc = gp.Describe(r'ACTUAL\LINEAS'). The following Error is written down in a log file: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;RuntimeError: ERROR 999999: Error executing function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;PerimetrosAFrentes.py works correctly and gp is properly created, but I donÂ´t figure out why PerimetrosAFrentes.exe colapses in gp.Describe. Any advice will be appreciated.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Aug 2011 10:40:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/errors-when-converting-py-to-exe-due-to-arcpy/m-p/204756#M15752</guid>
      <dc:creator>Juan_FranciscoMartínez_Carmona</dc:creator>
      <dc:date>2011-08-04T10:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: Errors when converting .py to .exe due to arcpy module</title>
      <link>https://community.esri.com/t5/python-questions/errors-when-converting-py-to-exe-due-to-arcpy/m-p/204757#M15753</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is there a reason you're compiling to an .exe? To obscure the code or because you're bundling third party modules? If you're just trying to obscure the code, you can have two files (in the same directory) like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;tool_implementation.py&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
def main():
&amp;nbsp;&amp;nbsp; &amp;lt;your geoprocessing script&amp;gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;tool_gp.py&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import tool_implementation
tool_implementation.main()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then set the path of the script tool to tool_gp.py in your toolbox, and run it once. Once tool_implementation.pyc exists, you can delete tool_implementation.py and your implementation will be obscured.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:08:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/errors-when-converting-py-to-exe-due-to-arcpy/m-p/204757#M15753</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2021-12-11T10:08:56Z</dc:date>
    </item>
    <item>
      <title>Re: Errors when converting .py to .exe due to arcpy module</title>
      <link>https://community.esri.com/t5/python-questions/errors-when-converting-py-to-exe-due-to-arcpy/m-p/204758#M15754</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for your answer. The main goal is to obscure the code as you rightly supposed, but I am unable to make it works. I wrote the following script:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;obscure.py&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import PerimetrosAFrentes
PerimetrosAFrentes.Principal()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;but it gives back the same Error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
File "W:\0_FUENTES_PROGRAMAS\DOCUMENTACION_INCENDIOS\DOCUMENTACION_INCENDIOS\PerimetrosAFrentes.py", line 34, in Principal
&amp;nbsp;&amp;nbsp;&amp;nbsp; fc_li_a = gp.Describe(r"ACTUAL\LINEAS").CatalogPath
RuntimeError: ERROR 999999: Error executing function.&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:08:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/errors-when-converting-py-to-exe-due-to-arcpy/m-p/204758#M15754</guid>
      <dc:creator>Juan_FranciscoMartínez_Carmona</dc:creator>
      <dc:date>2021-12-11T10:08:59Z</dc:date>
    </item>
    <item>
      <title>Re: Errors when converting .py to .exe due to arcpy module</title>
      <link>https://community.esri.com/t5/python-questions/errors-when-converting-py-to-exe-due-to-arcpy/m-p/204759#M15755</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You may need to either use a full path to your object or set the arcpy.env.workspace value before your Describe:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.env.workspace = os.path.abspath(os.path.dirname(__file__))&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Aug 2011 17:26:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/errors-when-converting-py-to-exe-due-to-arcpy/m-p/204759#M15755</guid>
      <dc:creator>JasonScheirer</dc:creator>
      <dc:date>2011-08-05T17:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: Errors when converting .py to .exe due to arcpy module</title>
      <link>https://community.esri.com/t5/python-questions/errors-when-converting-py-to-exe-due-to-arcpy/m-p/204760#M15756</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for your answer. I use 'Describe' precisely to get full path to a feature class from a feature layer in ArcMap, so I cannot use full path. Nevertheless, your answer gave me a good cue: the path to the geodatabase can be written in a text file where the Python file is, "os.path.dirname(__file__)". When access the feature class is required, the code reads this text file and builds the full path to the feature class. The problem is over.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Aug 2011 10:11:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/errors-when-converting-py-to-exe-due-to-arcpy/m-p/204760#M15756</guid>
      <dc:creator>Juan_FranciscoMartínez_Carmona</dc:creator>
      <dc:date>2011-08-18T10:11:17Z</dc:date>
    </item>
  </channel>
</rss>

