Cannot start subprocess or os.system(command) with 'import arcpy'

12-03-2020 12:54 PM
New Contributor II

I need to call a python script from another script, and not wait (this is a script to start multiple other scripts).   

I have three different methods of calling the script - execfile(), os.system(), and subprocess.popen().   These all work - but, the first one forces the program to wait; and the other ones will fail when it tries to import arcpy.  I suspect it is something to do with my 64-bit background geoprocessing, which I just reinstalled this morning.   The error that occurs when importing arcpy is this:

"Traceback (most recent call last):
File "f:\scratch\", line 5, in <module>
import arcpy
File "c:\program files (x86)\arcgis\desktop10.8\ArcPy\arcpy\", line 22, in <module>
from arcpy.geoprocessing import gp
File "c:\program files (x86)\arcgis\desktop10.8\ArcPy\arcpy\geoprocessing\", line 14, in <module>
from _base import *
File "c:\program files (x86)\arcgis\desktop10.8\ArcPy\arcpy\geoprocessing\", line 14, in <module>
import arcgisscripting
ImportError: DLL load failed: %1 is not a valid Win32 application."

I only have one installation of Python.  

I'm attaching two scripts: will call with the three different methods - if they are successful, they will write out text files indicating which method was used.    

I can't attach my scripts here, so they are pasted below:  The called script is commented out.  I'd sure appreciate any help with this!



import os
import subprocess
import sys
#import arcpy #works whether or not this is commented

''' script that's called by 3 methods below:
#script f:\\scratch\\

import sys
import time
outFile = sys.argv[1]
print (outFile)
import arcpy #if this is commented, all three methods work; otherwise only execfile works
print ("writing file")
newInputFile = "f:\\scratch\\" + outFile + ".txt"
inputfile = open(newInputFile, "w")


print ("execfile here:")
sys.argv = ['','file_from_execfile']


command = 'python f:\\scratch\\ file_from_command'
print ("command here:")

script = "f:\\scratch\\"
pythonExePath = r'C:\Python27\ArcGISx6410.8\python.exe'
pid = subprocess.Popen([pythonExePath, script, 'file_from_subprocess'], shell=False) # Call subprocess

print ("done")

Tags (1)
0 Kudos
1 Reply
MVP Esteemed Contributor

There are limits to 64 background geoprocessing.  Most would move to ArcGIS Pro

Background Geoprocessing (64-bit)—ArcMap | Documentation (


... sort of retired...
0 Kudos