Select to view content in your preferred language

Running python using server

2177
11
01-10-2024 06:20 AM
mody_buchbinder
Frequent Contributor

I have a machine that has Pro 3.1.4 & server 11.1

When I run in CMD the python from server ("C:\Program Files\ArcGIS\Server\framework\runtime\ArcGIS\bin\Python\envs\arcgispro-py3\python.exe") and try to import arcpy I get an error (see attachment) When I do it with the Pro python ("C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe") it works.

Both python version are the same (3.9.16)

I have tested it on a few machines that have both Pro & server installed. Some of them works, others do not.

Opened a case but the support does not have it on his machine.

Anybody have any idea?

When using the server python we should use the server license - this is the reason to use it.

Thanks

0 Kudos
11 Replies
alex_friant
Frequent Contributor

@ShaunWalbridge - Great suggestion, because I looked for it and bingo:
https://support.esri.com/en-us/bug/running-python-scripts-from-within-the-arcgis-enterpris-bug-00012...

I haven't tested the work around, but I'm about to try...

UPDATE: Resolved

The work around in that bug report didn't work for our situation. The issue persisted, even after uninstalling ArcGIS Pro all together.

However... I was able to resolve the issue and document it. I'll post that next...

0 Kudos
alex_friant
Frequent Contributor

Background: I was gratefully advised by Pro-West Associates that they have seen this issue before, and it appears to be related to if the user account experiencing the RuntimeError has signed into ArcGIS Pro before. The issue is tied to the Windows Registry, and while I can confirm that's the case with our user experiencing issues, it's not always the case, only that the fix lies in the registry. I had two other User accounts on the same server that had also opened ArcGIS Pro, but import arcpy worked just fine for them when using the ArcGIS Server Python 3 environment. So, replicating the issue is difficult.

These are the steps taken to solve the RuntimeError for that one user we needed to be able to use arcpy in the ArcGIS Server Python 3 environment:

  1. Make sure ArcGIS Pro is uninstalled (I also had ArcGIS Desktop 10.8 uninstalled as well, so if you still have that installed, you may want to take that into consideration at step 5 below)
  2. Sign in as user that was experiencing the issue of RuntimeError during import arcpy
  3. Open the Windows Registry Editor 

    Danger! Only do these steps in an environment you can recover catastrophic failures with, as Windows Registry is a core component of the Windows OS and can cause instability or corrupt the Windows OS. Proceed at own risk and if you know what you are doing!

  4. Note the settings for [Computer\HKEY_CURRENT_USER\Software\ESRI\ArcGISPro] are:                      alex_friant_7-1746559767075.png
  5. Make those > ArcGISPro settings look like so:                                    alex_friant_5-1746559564192.png
  6. Close Registry Editor
  7. Sign out the user from Windows, Sign the user back in 
  8. Test using Server’s Python 3 command prompt:                                                                       alex_friant_4-1746559529585.png

     

Reinstalling ArcGIS Pro after this point still results in a success as above. We will not have that user sign in to ArcGIS Pro out of concern that it might cause issues again (we've burned too much time on this issue at this point and must march forward.)

I hope this solution works for others - it was hard to discover!

0 Kudos