C:\Python27\ArcGISx6410.1 Python Traceback Info: File "\\snarf\am\div_lm\ds\gis\projects\lidar_hydro_all \lidar_hydro_child_v101.py", line 7, in <module> import arcpy Python Error Info: <type 'exceptions.ImportError'>: DLL load failed: %1 is not a valid Win32 application.
subprocess.Popen(['C:\\Python27\\ArcGISx6410.1\\python.exe', '\\\\snarf\\am\\div_lm\\ds\\gis\\projects\\lidar_hydro_all\\lidar_hydro_child_v101.py', 'C:\\csny490\\lidar_stream_build_new', '16'], shell=False)
Solved! Go to Solution.
Works for me in 64 bit python (using the following standalone script) and I have both 32 & 64 bit python installed.
import sys,subprocess
if len(sys.argv)>1:
import arcpy
print arcpy
print sys.executable
else:
cmd=['python',__file__,'foo']
proc=subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
exit_code=proc.wait()
stdout,stderr=proc.communicate()
print '\n'.join((str(exit_code),stdout,stderr))
This prints:
0
<module 'arcpy' from 'c:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\__init__.py'>
C:\Python27\ArcGISx6410.1\python.exe
Before running, I have a batch file to set up some environment variables:
@echo off
set PYTHONHOME=C:\Python27\ArcGISx6410.1
set PATH=
set PATH=%WINDIR%;%WINDIR%\system32
set PATH=%PYTHONHOME%;%PATH%
A couple of other things to try...
1 - make sure you're not calling subprocess.Popen with shell=True.
2 - try passing a custom "env" to subprocess.Popen with the above env vars, i.e (completely untested...):
env=os.environ.copy()
env['PATH']='%s;%s;%s' %
('C:\\Python27\\ArcGISx6410.1',
env['WINDIR'],
env['WINDIR']+'\\system32')
proc=subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,env=env)
(curtvprice did some editing to make the code visible again)
Works for me in 64 bit python (using the following standalone script) and I have both 32 & 64 bit python installed.
import sys,subprocess
if len(sys.argv)>1:
import arcpy
print arcpy
print sys.executable
else:
cmd=['python',__file__,'foo']
proc=subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
exit_code=proc.wait()
stdout,stderr=proc.communicate()
print '\n'.join((str(exit_code),stdout,stderr))
This prints:
0
<module 'arcpy' from 'c:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\__init__.py'>
C:\Python27\ArcGISx6410.1\python.exe
Before running, I have a batch file to set up some environment variables:
@echo off
set PYTHONHOME=C:\Python27\ArcGISx6410.1
set PATH=
set PATH=%WINDIR%;%WINDIR%\system32
set PATH=%PYTHONHOME%;%PATH%
A couple of other things to try...
1 - make sure you're not calling subprocess.Popen with shell=True.
2 - try passing a custom "env" to subprocess.Popen with the above env vars, i.e (completely untested...):
env=os.environ.copy()
env['PATH']='%s;%s;%s' %
('C:\\Python27\\ArcGISx6410.1',
env['WINDIR'],
env['WINDIR']+'\\system32')
proc=subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,env=env)
(curtvprice did some editing to make the code visible again)
env=os.environ.copy() env['PATH']='%s;%s;%s' %('C:\\Python27\\ArcGISx6410.1',env['WINDIR'],env['WINDIR']+'\\system32') proc=subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,env=env)
PYTHONPATH is a path that Python checks on load to find modulesYep - you are correct...
set Path=C:\Apps\Python27\ArcGISx6410.1;%Path%