<?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: Creating project package fails due to python toolbox in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/creating-project-package-fails-due-to-python/m-p/1265983#M66435</link>
    <description>&lt;P&gt;Is this in Pro 3.0.x or 3.1?&lt;/P&gt;&lt;P&gt;related&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-pro-questions/error-001659-when-creating-project-template/td-p/1221680" target="_blank"&gt;Error 001659 when Creating Project Template contai... - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;with no resolution&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/89710"&gt;@ShaunWalbridge&lt;/a&gt;&amp;nbsp; could you pass this on&lt;/P&gt;</description>
    <pubDate>Thu, 09 Mar 2023 14:54:38 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2023-03-09T14:54:38Z</dc:date>
    <item>
      <title>Creating project package fails due to python toolbox</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/creating-project-package-fails-due-to-python/m-p/1265950#M66430</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;I'm trying to create a project package in which the ArcGIS Pro project consists of one map with several featurelayers, standalone tables, a task and a python toolbox.&amp;nbsp; The python toolbox consists of 21 tools each in it's own .py file. The task and the tools within the python toolbox works ok. When I try to create a project package, I get an error which says&amp;nbsp; ERROR 001659: Consolidating toolbox.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've ran the "Analyze Tool for Pro" for all of the tools in the python toolbox, and there are no problems. When trying to run the "Consolidate Toolbox"-tool, I get an error saying&amp;nbsp;ModuleNotFoundError: No module named&amp;nbsp;'AndelerTilExcelTool', even though the module (tool) exists. Does anyone know what might be wrong?&lt;/P&gt;&lt;P&gt;Here's how I import the modules in the python toolbox (.pyt), the list of modules as been shortened.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# -*- coding: utf-8 -*-
import arcpy
import os
import sys

geovegScripts = os.path.join(os.path.dirname(__file__), "Scripts")
geovegSymbology = os.path.join(os.path.dirname(__file__), "Symbology")
sys.path.append(geovegScripts)

geovegModules = ['AndelerTilExcelTool',
                 'BearbeidAR5Tool',
                 'BearbeidBygningerTool',
                 'BeregnAndelerTool']

for module in geovegModules:
    if module in sys.modules:
        del(sys.modules[module])

from AndelerTilExcelTool import AndelerTilExcel
from BearbeidAR5Tool import BearbeidAR5
from BearbeidBygningerTool import BearbeidBygninger
from BeregnAndelerTool import BeregnAndeler

class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "Geoveg PythonToolbox"
        self.alias = "Geoveg verktøy"

        # List of tool classes associated with this toolbox
        self.tools = [AndelerTilExcel, BearbeidAR5, BearbeidBygninger, BeregnAndelerTool]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are some of the code from AndelerTilExcel, which is saved in the file AndelerTilExcelTool.py&lt;/P&gt;&lt;LI-CODE lang="python"&gt;class AndelerTilExcel(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Andeler til Excel"
        self.description = ""
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""
        params = None
        return params

    def isLicensed(self):
        """Set whether tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""
        return

    def execute(self, parameters, messages):
        """The source code of the tool."""
        try:
            fc_resultat = r"vegsone_bygninger"
            tittel = "Rapport andelsfordeling"
            rapport = r"C:\temp\Andelsfordeling.xlsx"

            #Oppretter ny excel-fil og legger til arbeidsark
            wb = openpyxl.Workbook()
            ws = wb.create_sheet("Andelsfordeling")
    
            #Legger inn overskrifter i arbeidsarket
            ws['A1'] = tittel
            ws['A2'] = "GNR/BNR"
            ws['B2'] = "Partsnummer"
            ws['D2'] = "Andel"

            #Henter informasjon om andelsfordelingen
            felter = ["SAK", "KOMM", "GNR", "BNR", "FNR", "SNR", 
                      "PARTSNUMMER", "ANDEL"]
            with arcpy.da.SearchCursor(fc_resultat, felter, sql_clause=(None, 'ORDER BY PARTSNUMMER DESC')) as cursor:
                linjeNr = 3
                for row in cursor:
                    sak = row[0]
                    kommune = row[1]
                    gnr = row[2]
                    bnr = row[3]
                    fnr = row[4]
                    snr = row[5]
                    partsnummer = row[6]
                    andel = row[7]

                    ws['A'+str(linjeNr)] = "{0}/{1}/{2}/{3}".format(gnr, bnr, fnr, snr)
                    ws['B'+str(linjeNr)] = partsnummer
                    ws['C'+str(linjeNr)] = andel

                    linjeNr += 1                

            #Lagrer Excel-filen
            wb.save(filename=rapport)
        except:
            # Get the traceback object
            tb = sys.exc_info()[2]
            tbinfo = traceback.format_tb(tb)[0]

            # Concatenate information together concerning the error into a message string
            pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
            msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"

            # Return Python error messages for use in script tool or Python window
            arcpy.AddError(pymsg)
            arcpy.AddError(msgs)

            # Print Python error messages for use in Python / Python window
            logging.error(pymsg)
            logging.error(msgs)
        return

    def postExecute(self, parameters):
        """This method takes place after outputs are processed and
        added to the display."""
        return&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As mentioned the python toolbox works ok, but not when consolidated or packaged.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2023 13:27:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/creating-project-package-fails-due-to-python/m-p/1265950#M66430</guid>
      <dc:creator>TorbjørnDalløkken2</dc:creator>
      <dc:date>2023-03-09T13:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: Creating project package fails due to python toolbox</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/creating-project-package-fails-due-to-python/m-p/1265983#M66435</link>
      <description>&lt;P&gt;Is this in Pro 3.0.x or 3.1?&lt;/P&gt;&lt;P&gt;related&amp;nbsp;&lt;A href="https://community.esri.com/t5/arcgis-pro-questions/error-001659-when-creating-project-template/td-p/1221680" target="_blank"&gt;Error 001659 when Creating Project Template contai... - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;with no resolution&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/89710"&gt;@ShaunWalbridge&lt;/a&gt;&amp;nbsp; could you pass this on&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2023 14:54:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/creating-project-package-fails-due-to-python/m-p/1265983#M66435</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2023-03-09T14:54:38Z</dc:date>
    </item>
    <item>
      <title>Re: Creating project package fails due to python toolbox</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/creating-project-package-fails-due-to-python/m-p/1265984#M66436</link>
      <description>&lt;P&gt;It's in ArcGIS Pro 3.0.x&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2023 14:55:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/creating-project-package-fails-due-to-python/m-p/1265984#M66436</guid>
      <dc:creator>TorbjørnDalløkken2</dc:creator>
      <dc:date>2023-03-09T14:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: Creating project package fails due to python toolbox</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/creating-project-package-fails-due-to-python/m-p/1266061#M66445</link>
      <description>&lt;P&gt;Pro works with Python 3.x. Is the script you are trying to use Python 3.x or 2.7. If 2.7 then you may need to upgrade your script to 3.x before it will work. Just a suggestion.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2023 17:05:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/creating-project-package-fails-due-to-python/m-p/1266061#M66445</guid>
      <dc:creator>JerryClark4</dc:creator>
      <dc:date>2023-03-09T17:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: Creating project package fails due to python toolbox</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/creating-project-package-fails-due-to-python/m-p/1266338#M66489</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/403781"&gt;@JerryClark4&lt;/a&gt;&amp;nbsp;I've used Python 3.x since the toolbox is for use in ArcGIS Pro &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 07:24:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/creating-project-package-fails-due-to-python/m-p/1266338#M66489</guid>
      <dc:creator>TorbjørnDalløkken2</dc:creator>
      <dc:date>2023-03-10T07:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: Creating project package fails due to python toolbox</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/creating-project-package-fails-due-to-python/m-p/1266982#M66555</link>
      <description>&lt;P&gt;I finally got something working here. In my scripts-folder, I forgot to add a __init__.py file. When adding this file, and changing my imports&amp;nbsp; like this, then it started working.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;geovegModules = ['Scripts.AndelerTilExcelTool',
                 'Scripts.BearbeidAR5Tool',
                 'Scripts.BearbeidBygningerTool',
                 'Scripts.BeregnAndelerTool']

for module in geovegModules:
    if module in sys.modules:
        del(sys.modules[module])

from Scripts.AndelerTilExcelTool import AndelerTilExcel
from Scripts.BearbeidAR5Tool import BearbeidAR5
from Scripts.BearbeidBygningerTool import BearbeidBygninger
from Scripts.BeregnAndelerTool import BeregnAndeler&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;But there's still one problem. I'm trying to define a logging handler in my toolbox (in class Toolbox __init__(self):&lt;/P&gt;&lt;LI-CODE lang="python"&gt;handler = logging.FileHandler(filename=r'C:\temp\Geoveg.log')
        formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s')
        handler.setFormatter(formatter)
        handler.setLevel(logging.DEBUG)
        logger = logging.getLogger()
        logger.setLevel(logging.DEBUG)
        logger.handlers = [handler]		&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;When trying to consolidate this, I get an FileNotFoundError.&amp;nbsp;[Errno 2] No such file or directory: 'C:\\commondata\\temp\\Geoveg.log'&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2023 08:35:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/creating-project-package-fails-due-to-python/m-p/1266982#M66555</guid>
      <dc:creator>TorbjørnDalløkken2</dc:creator>
      <dc:date>2023-03-13T08:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: Creating project package fails due to python toolbox</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/creating-project-package-fails-due-to-python/m-p/1278354#M67951</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/314803"&gt;@TorbjørnDalløkken2&lt;/a&gt;&amp;nbsp;based on the FileNotFoundError it looks like the specified log file C:\temp\Geoveg.log can't be found, and Python is looking for the file in C:\commondata\temp instead. Perhaps the directory doesn't exist, or you don't have access to it?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 16:30:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/creating-project-package-fails-due-to-python/m-p/1278354#M67951</guid>
      <dc:creator>HannesZiegler</dc:creator>
      <dc:date>2023-04-13T16:30:29Z</dc:date>
    </item>
  </channel>
</rss>

