ArcPy fails to import when not logged into host machine

Discussion created by shane.buscher on Nov 8, 2018
Latest reply on Mar 14, 2019 by shane.buscher

I am trying to run a python script on a server that I am not logged into. The script runs fine when I log into the server and execute. However, when the python script is executed through an automated process (not logged in) I receive the following error: 

Traceback (most recent call last):
  File ".\Python\Scripts\", line 1, in <module>
    import arcpy
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\", line 72, in <module>
    from arcpy.geoprocessing import gp
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\", line 14, in <module>
    from ._base import *
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\", line 14, in <module>
    import arcgisscripting
RuntimeError: Not signed into Portal.

arcpy is unable to be imported because, for some unknown reason, it can't determine there is an available ArcGIS Pro license when not directly logged in. 

The automated process consists of an Octopus deployment task. Essentially Octopus has a Windows service run by the Local System account. When a deployment occurs the service invokes a local powershell script that kicks off the python script. I tried switching the account that runs the service to a local administrator to no avail. Not sure where to go from here since I can successfully run the powershell script when logged in. 

How do I get this to work?