Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask app with ArcGIS, Arcpy does not run

I have a script that gets a table from MSSQL database and then registers it with ArcGIS. It uses several other arcpy methods as well. I tried to combine it with Flask and developed an HTML interface where you can specify tables. The script runs on console perfectly well, however, when running with Flask on http://127.0.0.1:5000/ , the arcpy functions do not run, then the app throws errors.

I am using my local python directory, so I do not have any problem with importing arcpy on flask. So, I am able to use pymssql functions and create a new table, however when it comes to arcpy function, It throws does not exist error, however, the table exists. I feel like there is something wrong with running arcpy with Flask, but any help would be appreciated.

(2) I tried the same thing in Django but I am having the same problem.

Thanks

forms.py

class createGISLayer(FlaskForm):
    tCreateLayer = SubmitField('Create GIS Layer')

DashboardMain()

   try:
        cursor.execute(QueryCreate)
        print ("Table Created.")
        print(self.dbTablePath)
        descTable = arcpy.Describe(self.dbTablePath)

    except arcpy.ExecuteError:
        print(arcpy.GetMessages())

app.py

if formCreate.tCreateLayer.data and formCreate.validate_on_submit():
    if myLayer is not None:
        try:
            print("Create GIS Layer")
            myLayer.dashboardMain()
            flash('GIS Layer created!', 'success')

        except Exception as e:
            print(e.message)
            flash(e.message, 'danger')

index.html

<!-- Create GIS Layer  -->
<div class="content-section">
<form name='idCreateGISLayer' action="" method="POST">
<table style="height: auto; margin-left: auto; margin-right: auto; width: 600px;">
<tbody>
<tr>
    {{ formCreate.hidden_tag() }}
    <td style="height: 39px; width: 259px">
        <h2 style="text-align: left;"><font size="3"><strong>(2) Create </strong></font></h2>
    </td>
    <td style="text-align: left; height: 39px;">
        <div class="auto-style2">                                                                
            {{ formCreate.tCreateLayer(class="btn btn-outline-info")}}
        </div>
    </td>
 </tr>
 </tbody>
 </table>
 </form>
 </div>

ERROR

Table Created.
F:\Projects\Dashboard\Publish.sde\Publish.dbo.A_WebT1
"F:\Projects\Dashboard\Publish.sde\Publish.dbo.A_WebT1" does not exist

screenshot

Table exists

like image 672
Efkan Avatar asked Aug 31 '25 15:08

Efkan


1 Answers

IIRC, ArcGIS maintains it's own python environment (and used to install it over existing installations, ick). So unless you're using that environment when you launch/run flask, you're likely not getting the config/resources loaded that are needed to support Arcpy functions. It's like trying to load a library installed into a different python virtual environment. You can provide the path, but if it requires any additional content or configuration from it's own venv, it won't work.

like image 160
incongruentDoughnut Avatar answered Sep 02 '25 21:09

incongruentDoughnut