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\DeployGeodatabase.py", line 1, in <module>
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\__init__.py", line 72, in <module>
from arcpy.geoprocessing import gp
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\__init__.py", line 14, in <module>
from ._base import *
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 14, in <module>
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?
The most common ArcGIS Pro license is Named User. If you are using Named User licensing, there is no single license on the machine for ArcGIS Pro. When ArcGIS Pro launches, it grabs a license for a user based on how the license information is configured for that user. If ArcGIS Pro has never been launched by a user, or some registry modifications haven't been made, ArcPy will have no idea how to obtain a license when running under that user's credentials.
Can you test running the script under your credentials?
Thanks for your reply Joshua. I can run the script fine when I physically log into the server with my credentials, but that's not really helpful. I need to have the script be executed when logged off. This is more about an automated process kicking off the script offline. Even if I remote into the server via a powershell session (passing my credentials) and run the script, arcpy still can't be imported. This seems to indicate you have to be logged into Windows to get a Pro license to use arcpy. Ugly.
I am using a named license. Are you hinting that using a single use license could resolve the problem? Is there a registry setting that can be tweaked?
If you search GeoNet, you will find getting Pro-based ArcPy to run as a scheduled task has been a challenge for quite a few, but it has been made to work. Some of those threads provide good information. I am not sure if you have read them and tried any of the suggestions, so I may repeat what I have already said elsewhere on GeoNet.
There aren't many specifics here to go on, so feedback may be limited compared to previous discussions on this topic in GeoNet. A few questions to start. How is your licensing currently configured for Pro on the machine? You mention Named User, is it configured for offline access or automatic login? Regarding your comment, "the script is executed through an automated process...". Are you using Task Scheduler or some other mean of automating it, and can you provide some specific of how that is configured.
I can get the script to work through a scheduled task when not logged in. The reason is Task Scheduler directly supports logins (the radio button 'Run whether user is logged on or not'). As mentioned in the original post, I'm using Octopus to run a powershell script on the machine that invokes the python script. Here's the workflow:
There is no scheduled task in this situation. Octopus runs as a service on the ArcGIS Pro machine, running under the Local System account. This is what kicks off the powershell script. I've even run the service under my domain account, which is the account I use to log into the machine and use ArcGIS Pro. I still get the arcpy import error. I get the same error also if I shell into the machine with powershell using my domain credentials and try running the script.
My ArcGIS Pro License is configured as 'Sign me in automatically'. I know this works because I can use a scheduled task succesfully with arcpy.
If you need any more info please let me know.
In my situation I did get things working. You will need to log into the server with the account that you want to run arcpy under and open ArcGIS Pro. This creates the esri profile under C:\Users\<user>\AppData\Roaming\Esri required to get around the error. I recommend using a single use license of ArcGIS Pro for this user.
Yes, the part about actually starting up Pro under the account that your script will run has tripped me up. Had it running beautifully on one server and then it didn't work on box #2. Well, I had never opened Pro under the login. So good point!
Hi Mary. I had the same issue with getting logged out. Requiring authentication through Portal to use a Python library is beyond ridiculous. Fortunately there is a workaround. You need to use a dedicated ArcPro single use license on the machine. Good luck!