Failed Import

277 views
Skip to first unread message

Jamie Jackson

unread,
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,
Jamie
<pre>== TRACE ==

Traceback (most recent call last):
  File "C:\inetpub\satelliteEligibilityFresh265\isapi-wsgi\_loader.py", line 42, in <module>
    from appinit import __wsgiapp__ as wsgiapp
  File "C:\inetpub\satelliteEligibilityFresh265\isapi-wsgi\appinit.py", line 17, in <module>
    from hello import app
  File "C:\inetpub\satelliteEligibilityFresh265\isapi-wsgi\hello.py", 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\arcinfo.py", line 15, in <module>
    import arcgisscripting
ImportError: DLL load failed: %1 is not a valid Win32 application.


== ENVIRON ==

{'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',
 'COMPUTERNAME': 'IP-0AC32EFF',
 'COMSPEC': 'C:\\Windows\\system32\\cmd.exe',
 'CONTENT_LENGTH': '0',
 'CONTENT_TYPE': '',
 'DFSTRACINGON': 'FALSE',
 'FP_NO_HOST_CHECK': 'NO',
 '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',
 'IIS_EXTENSION_PATH': '',
 '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',
 'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC',
 'PATH_INFO': '/',
 'PROCESSOR_ARCHITECTURE': 'AMD64',
 'PROCESSOR_IDENTIFIER': 'Intel64 Family 6 Model 23 Stepping 10, GenuineIntel',
 'PROCESSOR_LEVEL': '6',
 'PROCESSOR_REVISION': '170a',
 'PROGRAMDATA': 'C:\\ProgramData',
 'PROGRAMFILES': 'C:\\Program Files',
 'PROGRAMFILES(X86)': 'C:\\Program Files (x86)',
 'PUBLIC': 'C:\\Users\\Public',
 'QUERY_STRING': '',
 'REMOTE_ADDR': '127.0.0.1',
 'REMOTE_USER': '',
 'REQUEST_METHOD': 'GET',
 'SCRIPT_NAME': '',
 'SERVER_NAME': 'jjfake.localhost',
 'SERVER_PORT': '82',
 'SERVER_PROTOCOL': 'HTTP/1.1',
 'SYSTEMDRIVE': 'C:',
 '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',
 'USERDOMAIN': 'WORKGROUP',
 'USERNAME': 'IP-0AC32EFF$',
 '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:\\inetpub\\satelliteEligibilityFresh265\\Lib\\site-packages\\setuptools-0.6c12dev_r88846-py2.6.egg',
 'C:\\inetpub\\satelliteEligibilityFresh265\\Lib\\site-packages',
 'C:\\Program Files (x86)\\ArcGIS\\Server10.0\\bin',
 'C:\\inetpub\\satelliteEligibilityFresh265\\Lib\\site-packages\\pip-1.0.2-py2.6.egg',
 'C:\\Program Files (x86)\\ArcGIS\\Desktop10.0\\arcpy',
 'C:\\Program Files (x86)\\ArcGIS\\Server10.0\\ArcToolbox\\Scripts',
 'C:\\inetpub\\satelliteEligibilityFresh265\\isapi-wsgi',
 'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg',
 'C:\\Python27\\lib\\site-packages\\virtualenv-1.6.4-py2.7.egg',
 'C:\\inetpub\\satelliteEligibilityFresh265\\Lib\\site-packages\\setuptools-0.6c12dev_r88846-py2.6.egg',
 'C:\\inetpub\\satelliteEligibilityFresh265\\Lib\\site-packages\\pip-1.0.2-py2.6.egg',
 'C:\\Python27\\lib\\site-packages\\pip-1.0.2-py2.7.egg',
 'C:\\Windows\\system32\\python27.zip',
 'C:\\Python27\\Lib',
 'C:\\Python27\\DLLs',
 'C:\\Python27\\Lib\\lib-tk',
 'c:\\windows\\system32\\inetsrv',
 'C:\\Python27',
 'C:\\Python27\\lib\\site-packages',
 'C:\\Python27\\lib\\site-packages\\win32',
 'C:\\Python27\\lib\\site-packages\\win32\\lib',
 'C:\\Python27\\lib\\site-packages\\Pythonwin',
 'C:\\inetpub\\satelliteEligibilityFresh265\\Lib\\site-packages',
 '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

unread,
Aug 19, 2011, 10:36:10 AM8/19/11
to isapi_w...@googlegroups.com
Maybe related:

http://groups.google.com/group/isapi_wsgi-dev/browse_thread/thread/3fa2b485ec2281d/

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
setup.py ...). At that point, it worked. Why it worked, I have no idea.

--------------------------------------
Randy Syring
Intelicom
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 isapi_w...@googlegroups.com.
> To unsubscribe from this group, send email to
> isapi_wsgi-de...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/isapi_wsgi-dev?hl=en.

Chris Lambacher

unread,
Aug 19, 2011, 10:57:28 AM8/19/11
to isapi_w...@googlegroups.com
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
%PYTHONINSTALLDIR%\Lib\distutils\msvc9compiler.py

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.

-Chris

--
Christopher Lambacher
ch...@kateandchris.net

Chris Lambacher

unread,
Aug 19, 2011, 11:25:51 AM8/19/11
to isapi_w...@googlegroups.com
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
yourscript.py") instead of "python.exe yourscript.py" or
"yourscript.py" without using python.exe in front of it :(

-Chris

--
Christopher Lambacher
ch...@kateandchris.net

Reply all
Reply to author
Forward
0 new messages