Select to view content in your preferred language

Calling ArcGIS Pro Python from ArcGIS Server 10.6.1

856
3
09-30-2021 01:17 PM
PatSmyth
New Contributor III

We have enterprise 10.6.1 single machine deployment (windows). ArcGIS Pro 2.7 is installed on same EC2 instance Portal/Server are installed on. I am attempting to do the following:

  1. GP Initiated through REST service call
  2. GP calls a batch file through python SubProcess (import subprocess and popen method) like so:

 

p = Popen([matrix_run_bat], stdout=PIPE, stderr=PIPE)
p.wait()
output, errors = p.communicate()
print([p.returncode, errors, output])
arcpy.AddMessage([p.returncode, errors, output])
if p.returncode or errors:
    print('something went wrong...')
    arcpy.AddMessage('something went wrong...{0}, {1}'.format(errors, output))

 

3. The batch file triggers another python file using ArcGIS Pro Python like :

 

@echo Starting Telr Matrix
call "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3-clone-telr-matrix\python" "D:\2nform\TELR_GRID\Pat_Dev\telr-matrix\main.py" "run_telr_matrix" 10 2021
@echo Finished​

 

 

The python env in first argument of the bat file is a clone in my ArcGIS Pro env. The error I get when running gp service is that a module (that I know has been installed in the bat specified python env) in main.py is missing:

 

esriJobMessageTypeInformative: something went wrong...b'Traceback (most recent call last):\r\n File "D:\\2nform\\TELR_GRID\\Pat_Dev\\telr-matrix\\main.py", line 3, in <module>\r\n from telr_matrix.run_telr_matrix import RunTelrMatrix\r\n File "D:\\2nform\\TELR_GRID\\Pat_Dev\\telr-matrix\\telr_matrix\\run_telr_matrix.py", line 4, in <module>\r\n from telr_matrix.cbmp.cbmp import CBMP\r\n File "D:\\2nform\\TELR_GRID\\Pat_Dev\\telr-matrix\\telr_matrix\\cbmp\\cbmp.py", line 5, in <module>\r\n import geopandas as gpd\r\nModuleNotFoundError: No module named \'geopandas\'\r\n', b'Starting Telr Matrix\r\n\r\nC:\\Program Files\\ArcGIS\\Server\\framework\\runtime\\jre\\bin>call "C:\\Program Files\\ArcGIS\\Pro\\bin\\Python\\envs\\arcgispro-py3-clone-telr-matrix\\python.exe" "D:\\2nform\\TELR_GRID\\Pat_Dev\\telr-matrix\\main.py" "run_telr_matrix" 10 2021 \r\nFinished\r\n'

 

 

It looks as if it is still attempting to run the python script using the 10.6.1 Server python version instead of the ArcGIS Pro python specified in bat file. When I run subprocess locally from a variety of default python env, it will use the correct env specified in the bat call. 

And just FYI, the reason I want to use the ArcGIS Pro env and not update the default Server 10.6.1 env for the gp task is because of this ominous bit about updating module in default server env at 10.6.1:

You will be modifying the defaultArcGIS Serverconda environment. In the event of environment corruption, you will need to re-install yourArcGIS Server. If you are usingArcGIS Server10.7 or later, a safer process to deploy your Python packages is available.

So, should it be possible to call ArcGIS Pro Python from ArcGIS Server 10.6.1 python gp service using a subprocess that runs a bat script that specifies to use ArcGIS Pro Python? Thanks!

0 Kudos
3 Replies
cdickerson
New Contributor III

Hi, 

I don't have an exact answer for you but your Enterprise deployment and your Pro version are out of sync. There is a chance that if you are running it through Server it might be running on the older ArcMap runtime vs the new runtime that would be associated with Pro. (pardon if my terminology is a little off but this might help with your search for a solution)

0 Kudos
PatSmyth
New Contributor III

Thanks for the help. I know for certain the Enterprise python and Pro python are out of sync. This is part of the reason I would like to use the subprocess + bat script to call my python program using the Pro python runtime rather than the difficult/risky to update Server python runtime. 

 

0 Kudos
IhabHassan
Esri Contributor

Hi @PatSmyth 
If the role of the GP service is just to kickstart the python code, then it might be easier to do so using another RESTful service technology , like NodeJS or DotNet.
I don't have a workable code sample, but something like https://www.npmjs.com/package/python-shell can be a good start, which will allow you to run python from a specific python environment.

Regards
Ihab