ArcPy fails to import when not logged into host machine

3637
11
11-08-2018 08:23 AM
ShaneBuscher1
New Contributor III

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>
    import arcpy
  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>
    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? 

Tags (2)
0 Kudos
11 Replies
JoshuaBixby
MVP Esteemed Contributor

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?

0 Kudos
ShaneBuscher1
New Contributor III

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? 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

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.

0 Kudos
ShaneBuscher1
New Contributor III

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:

  1. A build is kicked off on a separate build server.
  2. The python script that needs to be run is found within our source control (git) and packaged up (zipped).
  3. The package is deployed via Octopus to the the machine with ArcGIS Pro installed. 
  4. Octopus unzips the package with the python script
  5. Octopus runs a powershell script that executes the python script on the machine.

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. 

Regards,

Shane

0 Kudos
BrandonLongenberger
New Contributor

Shane,

Where you able to come up with a solution to fix this issue? I am having the same problem with one of our servers.

Brandon

0 Kudos
ShaneBuscher1
New Contributor III

Brandon,

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.  

Regards,

Shane

Arne_Gelfert
Regular Contributor

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!

0 Kudos
maryandrews
New Contributor III

I think the problem I am having is related so I'll ask for help here.  I have a number of batch processes that run python scripts via task scheduler.  They run great and then all the sudden a few weeks into them running flawlessly my scripts fail.  Turns out my user name is getting signed out of ArcPro.  I have learn that automatic sign in is only good for 14 days and then you are no longer signed it.  If I manually open ArcPro and sing in my scripts go back to working fine.  I tired adding arcpy.SingInToPortal  to my scripts but it doesn't seem to sign me in to ArcPro and therefor does not fix the problem.  

 

If I remember correctly, arcmap with 2.7 had a way to check out a licence.  So I tested checking out an extension in 3.x for Arcpro.  Extension check out fine but did not sign me in.

 

Any help would be greatly appreciated.  I don't want to have to manually start ArcPro and sign in every 13 days.

 

Buy the way, I called Technical support to ask how to "sign in" via my python script and I have not gotten an answer back yet.  

 

PLEASE HELP


					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
ShaneBuscher1
New Contributor III

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!