Failed Import

Skip to first unread message

Jamie Jackson

Aug 17, 2011, 10:50:46 PM8/17/11
to isapi_wsgi-dev
Hello again, folks,

Now that I got isapi-wsgi working, I'd just started getting into the meat of my app but have another hurdle.

In order to work with ArcGIS (arcinfo & arcpy modules), I installed the same version of Python that it comes bundled with (2.6.5, 32bit). Into this base installation, I installed pip, isapiwsgihelper, isapi-wsgi, and virtualenv.

I created a new virtualenv based on this, into which I installed flask and ran iwhelper.

The basic flask app works from the browser, so I know I've got the handler set up.

However, if I try to import arcinfo (the first thing that must be imported in an arcpy app), I get the error, below.

On the other hand, in a python shell in the virtualenv, if I import arcinfo, there's no problem.

I think it was Mark that mentioned that sys.path will be different for an ISAPI call versus a cmd call. This seems to be quite true, as it's got some weird stuff in there in an ISAPI call (e.g., paths associated with a Python 2.7 installation). However, this seems to defeat the isolation of a virtualenv, and I wonder if some of these other paths are interfering.

Could you help me understand this differing sys.path thing, and let me know if you have any ideas for solving the problem at hand?

Thanks again,
<pre>== TRACE ==

Traceback (most recent call last):
  File "C:\inetpub\satelliteEligibilityFresh265\isapi-wsgi\", line 42, in <module>
    from appinit import __wsgiapp__ as wsgiapp
  File "C:\inetpub\satelliteEligibilityFresh265\isapi-wsgi\", line 17, in <module>
    from hello import app
  File "C:\inetpub\satelliteEligibilityFresh265\isapi-wsgi\", line 5, in <module>
    import arcinfo # important that this goes before the arcpy import. it pulls the arcinfo license
  File "C:\Program Files (x86)\ArcGIS\Server10.0\arcpy\", line 15, in <module>
    import arcgisscripting
ImportError: DLL load failed: %1 is not a valid Win32 application.


{'AGSDESKTOPJAVA': 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.0\\',
 'AGSSERVERJAVA': 'C:\\Program Files (x86)\\ArcGIS\\Server10.0\\',
 'ALLUSERSPROFILE': 'C:\\ProgramData',
 'APPDATA': 'C:\\Windows\\system32\\config\\systemprofile\\AppData\\Roaming',
 'APP_POOL_ID': 'satelliteEligibility',
 'COMMONPROGRAMFILES': 'C:\\Program Files\\Common Files',
 'COMMONPROGRAMFILES(X86)': 'C:\\Program Files (x86)\\Common Files',
 'COMSPEC': 'C:\\Windows\\system32\\cmd.exe',
 'HTTPS': 'off',
 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
 'HTTP_ACCEPT_CHARSET': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
 'HTTP_ACCEPT_ENCODING': 'gzip, deflate',
 'HTTP_ACCEPT_LANGUAGE': 'en-us,en;q=0.5',
 'HTTP_CACHE_CONTROL': 'no-cache',
 'HTTP_CONNECTION': 'keep-alive',
 'HTTP_HOST': 'jjfake.localhost:82',
 'HTTP_PRAGMA': 'no-cache',
 'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 6.0; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0',
 'LOCALAPPDATA': 'C:\\Windows\\system32\\config\\systemprofile\\AppData\\Local',
 'OS': 'Windows_NT',
 'PATH': 'C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;c:\\Program Files (x86)\\Microsoft SQL Server\\100\\Tools\\Binn\\;c:\\Program Files\\Microsoft SQL Server\\100\\Tools\\Binn\\;c:\\Program Files\\Microsoft SQL Server\\100\\DTS\\Binn\\;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;c:\\Program Files (x86)\\Microsoft SQL Server\\100\\Tools\\Binn\\VSShell\\Common7\\IDE\\;c:\\Program Files (x86)\\Microsoft SQL Server\\100\\DTS\\Binn\\;C:\\Program Files (x86)\\WinMerge;C:\\MinGW\\bin;C:\\Python27\\;C:\\Python27\\Scripts;C:\\Program Files\\Internet Explorer',
 'PATH_INFO': '/',
 'PROCESSOR_IDENTIFIER': 'Intel64 Family 6 Model 23 Stepping 10, GenuineIntel',
 'PROGRAMDATA': 'C:\\ProgramData',
 'PROGRAMFILES': 'C:\\Program Files',
 'PROGRAMFILES(X86)': 'C:\\Program Files (x86)',
 'PUBLIC': 'C:\\Users\\Public',
 'SERVER_NAME': 'jjfake.localhost',
 'SERVER_PORT': '82',
 'SYSTEMROOT': 'C:\\Windows',
 'TEMP': 'C:\\Windows\\TEMP',
 'TMP': 'C:\\Windows\\TEMP',
 'TRACE_FORMAT_SEARCH_PATH': '\\\\winseqfe\\release\\Windows6.0\\lh_sp2rtm\\6002.18005.090410-1830\\amd64fre\\symbols.pri\\TraceFormat',
 'USERPROFILE': 'C:\\Windows\\system32\\config\\systemprofile',
 'WINDIR': 'C:\\Windows',
 'isapi.ecb': <EXTENSION_CONTROL_BLOCK object at 0x000000000338FB00>,
 'wsgi.errors': <PyTraceObject object at 0x0000000002EAB458>,
 'wsgi.file_wrapper': <class wsgiref.util.FileWrapper at 0x0000000002F413A8>,
 'wsgi.input': <isapi_wsgi.ISAPIInputWrapper instance at 0x00000000035EC348>,
 'wsgi.multiprocess': False,
 'wsgi.multithread': False,
 'wsgi.run_once': False,
 'wsgi.url_scheme': 'http',
 'wsgi.version': (1, 0)}

== SYS.PATH ==

['C:\\Program Files (x86)\\ArcGIS\\Desktop10.0\\ArcToolbox\\Scripts',
 'C:\\Program Files (x86)\\ArcGIS\\Server10.0\\arcpy',
 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.0\\bin',
 'C:\\Program Files (x86)\\ArcGIS\\Server10.0\\bin',
 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.0\\arcpy',
 'C:\\Program Files (x86)\\ArcGIS\\Server10.0\\ArcToolbox\\Scripts',
 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.0\\bin',
 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.0\\arcpy',
 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.0\\ArcToolbox\\Scripts',
 'C:\\Program Files (x86)\\ArcGIS\\Server10.0\\bin',
 'C:\\Program Files (x86)\\ArcGIS\\Server10.0\\arcpy',
 'C:\\Program Files (x86)\\ArcGIS\\Server10.0\\ArcToolbox\\Scripts']</pre>

Randy Syring

Aug 19, 2011, 10:36:10 AM8/19/11
Maybe related:

I know there can be issues with the way python gets built, manifests,
etc. I can't speak to a whole lot of that, as I don't really understand
it all, but I do know that I had to re-build pyodbc at one point to get
it to run under IIS. It would run fine from the console, but not under
IIS. I ended up commenting out some code in one of python's core files
(probably in distutils) and then had to re-compile pyodbc (python ...). At that point, it worked. Why it worked, I have no idea.

Randy Syring
Direct: 502-276-0459
Office: 502-212-9913

For the wages of sin is death, but the
free gift of God is eternal life in
Christ Jesus our Lord (Rom 6:23)

> 'wsgi.input':<isapi_wsgi.ISAPIInputWrapper instanceat0x00000000035EC348>,

> --
> You received this message because you are subscribed to the Google
> Groups "isapi_wsgi-dev" group.
> To post to this group, send email to
> To unsubscribe from this group, send email to
> For more options, visit this group at

Chris Lambacher

Aug 19, 2011, 10:57:28 AM8/19/11
Randy is right about modules importing C modules under IIS. starting
with Python 2.6 python extensions filter out the msvcrt info from the
manifest attached to them because they are supposed to inherit C
runtime in the manifest of the python executable. PyWin32 does not
seem to attach the manifest in its own DLLs (or for some reason they
are not inherited in the same way that they are from the python
executable). I have had to recompile *all* my C extensions with the
manifest including the msvcrt reference. In order to be able to do
that you need to modify

For python 2.6 add "raise IOError()" after the try: on line 658

For python 2.7 comment out the call to "self._remove_visual_c_ref" on line 673

In either case you should see this comment, which documents what we
are trying to avoid here:
# Remove references to the Visual C runtime, so they will
# fall through to the Visual C dependency of Python.exe.
# This way, when installed for a restricted user (e.g.
# runtimes are not in WinSxS folder, but in Python's own
# folder), the runtimes do not need to be in every folder
# with .pyd's.

Of course, as the comment indicates, you may then have other problems :(

I got this info from a Python bug, but I can't find it to reference it
right now.


Christopher Lambacher

Chris Lambacher

Aug 19, 2011, 11:25:51 AM8/19/11
Jamie: About the versions of python you mention in your original
question. Do you have more than one version of Python installed? You
need to make sure you are using the same version everywhere (your
virtualenv, pywin32, isapi-wsgi, etc) and it looks like that might not
be the case.

I would guess that you "installed your app" with the Python 2.7
version of the python.exe. Try installing it again while providing the
full path the the Python 2.6 executable ("c:\python26\python.exe") instead of "python.exe" or
"" without using python.exe in front of it :(


Christopher Lambacher

Reply all
Reply to author
0 new messages