0

I have a script with ArcGIS using arcpy model. And I want to combine it with Django. The script runs on console successfully, however, when running with Django, I find the arcpy functions do not run. So I make a simple test for it, and get the same result.

test.py

import arcpy
import os

def test_arcpy():
    tempFolder = arcpy.env.scratchFolder
    tempGDBPath = os.path.join(tempFolder, 'test.gdb')
    arcpy.env.overwriteOutput = True
    if not arcpy.Exists(tempGDBPath):
        arcpy.AddMessage('create..')
        arcpy.CreateFileGDB_management(tempFolder, 'test.gdb')
    return arcpy.Exists(tempGDBPath)

views.py

from django.http import HttpResponse
from . import test
def t(request):
    msg = str(test.test_arcpy())
    return HttpResponse(msg)

If I run the test.py in console, it return True.But if I run it in django, it always return false. If I cannot solve it , I cannot make more difficult script in django. Can you help me? I found the similar question in Flask app with ArcGIS, Arcpy does not run, but no solution in this question.

xiluzi
  • 13
  • 1

2 Answers2

0

I think I can use the subprocess model to run the arcpy script in console, and then return the console message back to the django function. But I really want to know whether arcpy can run with django or not.

xiluzi
  • 13
  • 1
0

i meet the same problem the same as you in Flask.

I check the source code in arcpy, found there is an bug in arcgisscripting.pyd file while i trigger arcpy.Exists() from Flask. And i lost any clew. After searching for some case on ESRI online blog, i certainly found that it's a bug in arcpy. So i advice u:

  1. try higher version arcpy.(my current version is 10.1)
  2. try to run your code in a console
  3. try to run message queue like from multiprocessing import Queue, Process
  4. try to not use the function. In my case, I avoid to use arcpy.Exists()
  5. try to use 64-bit arcpy in arcServer.
Jared Forth
  • 1,577
  • 6
  • 17
  • 32
Jiang
  • 1
  • 1