Select to view content in your preferred language

Deploying a Python + Flask application which can import ArcPy and the ArcGIS Python API to Windows Server

761
4
02-17-2025 03:18 PM
mfcallahan
Frequent Contributor
4 4 761

I recently started exploring the Flask web application framework for Python, but I ran into an issue when trying to deploy the application to Windows Server. My Flask application had a dependency on arcpy, which was available on my local development environment, but not on my server. As you are likely aware, the arcpy package is not available outside of the ArcGIS Pro Python environment, and I ran into quite a few issues with not being able to import and use these libraries. After some some googling, lots of trial and error, and a little help from Esri support, I was able to accomplish this task!

https://mfcallahan.com/2025/02/17/deploying-a-python-flask-application-which-can-import-arcpy-and-th...

Above is the link to my blog post which goes into deep detail on how to accomplish this, but at a high level, the steps needed to accomplish this are:

  • Copy app code to server
  • Clone the default "arcgispro-py3" environment
  • Activate your cloned ArcGIS Pro Python environment in Conda
  • Install the flask and wfastcgi dependencies
  • Copy file "wfastcgi.py" to the root app folder from the Python site-packages folder
  • Create a new application pool
  • Set app folder ownership to IIS AppPool
  • Add app to FastCGI Server Settings, using the cloned Python env
  • Set <handlers> in web.config file
4 Comments
HaydenWelch
MVP Regular Contributor

This is a really cool solution to using arcpy without spooling an enterprise server and just using a regular Pro install! If you don't mind I'm gonna move it over to the Blog section of this forum so it doesn't get lost in the flood of questions.

mfcallahan
Frequent Contributor

Thank you! I should have clarified - this method is indeed specific to deploying an application, which has a dependency on arcpy, to a server that does not have ArcGIS Enterprise installed. This has proven to be a possible solution for hosting microservices for GIS apps and tools in our organization which require rapid development, while also playing to the Python strengths of our team.

Raul_Jimenez
Esri Regular Contributor

Awesome tutorial Matthew!

I will share that internally with our doc team. Thanks for sharing it.

About your comment:

I should have clarified - this method is indeed specific to deploying an application, which has a dependency on arcpy, to a server that does not have ArcGIS Enterprise installed

I'm glad you mentioned this, I thought the same thing, especially when reading the following sentence: "That is to say, you can’t download and install Python, import arcpy or ArcGIS (the packages containing the ArcGIS Python API), and execute a script outside the ArcGIS ecosystem."

If I may, from my humble point of view I wanted to suggest how to rephrase this to make it more accurate: "That is to say, you can download and install the ArcGIS Python API on any machine (arcpy is not required), but you can’t execute arcpy-dependent functions outside the ArcGIS ecosystem."

Thanks again for taking the time to write this awesome tutorial, I'm sure it will be of great help for other developers.

Raul
P.S: I did this Google Colab a few weeks ago as an example to help another developer understand that it was possible.

AlfredBaldenweck
MVP Regular Contributor

Super cool! I think this may be helpful for a puzzle I've been working on.

About the Author
Hello, I'm Matt and I am a software developer in Phoenix, AZ
Labels