I'm packaging a project with an embedded python toolbox with the intent of sharing it with others via ArcGIS Online. The python tool imports a module and it looks like the path to that module is being incorrectly changed during consolidation.
The path to the imported module as I created it is:
E:\ROW_as_habitat\temp\test_dir
The path after the consolidation(I ran Package Product, uploaded the .ppkx to ArcGIS Online, then open the uploaded .ppkx in ArcGIS Online via the portal) is
C:\Users\DMORRI~1\AppData\Local\Temp\ArcGISProTemp1188\..\test_project_1\p20\test_dir
I would expect the fixed up path to point into the Packages directory, but this is pointing into the temp directory. I do see the module in what I believe is the proper place in under the Packages directory. In any case the import fails when I run the tool from the packaged project.
Here is the tool code as I created it in ArcGIS Pro
import arcpy
class Toolbox(object):
def __init__(self):
self.label = "Toolbox"
self.alias = ""
self.tools = [Tool]
class Tool(object):
def __init__(self):
self.label = "Tool"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
params = None
return params
def isLicensed(self):
return True
def updateParameters(self, parameters):
return
def updateMessages(self, parameters):
return
def execute(self, parameters, messages):
test_dir = r'E:\ROW_as_habitat\temp\test_dir'
arcpy.AddMessage(test_dir)
sys.path.append(test_dir)
import logger as row_logger
arcpy.AddMessage(row_logger.LOG_FILE)
return
Here is the code after the fixup
import sys, os, arcpy
g_ESRI_variable_1 = os.path.join(arcpy.env.scriptWorkspace,'..\\test_project_1\\p20\\test_dir')
import arcpy
class Toolbox(object):
def __init__(self):
self.label = "Toolbox"
self.alias = ""
self.tools = [Tool]
class Tool(object):
def __init__(self):
self.label = "Tool"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
params = None
return params
def isLicensed(self):
return True
def updateParameters(self, parameters):
return
def updateMessages(self, parameters):
return
def execute(self, parameters, messages):
test_dir = g_ESRI_variable_1
arcpy.AddMessage(test_dir)
sys.path.append(test_dir)
import logger as row_logger
arcpy.AddMessage(row_logger.LOG_FILE)
return