On Thursday, November 18, 2010, yccheok <[email protected]> wrote: > I am using Windows XP, and using Python run time from > http://www.python.org/ftp/python/2.7/python-2.7.msi > > If I am running in standalone application, import psycopg2 doesn't > cause me any trouble. However, when come to mod_wsgi + apache, I will > get the following error > > > [Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] mod_wsgi > (pid=2832): Target WSGI script 'C:/Projects/SandBox/web/script/ > index.py' cannot be loaded as Python module. > [Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] mod_wsgi > (pid=2832): Exception occurred processing WSGI script 'C:/Projects/ > SandBox/web/script/index.py'. > [Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] Traceback (most > recent call last): > [Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] File "C:/ > Projects/SandBox/web/script/index.py", line 9, in <module> > [Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] import > psycopg2 > [Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] File "build\ > \bdist.win32\\egg\\psycopg2\\__init__.py", line 65, in <module> > [Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] from > psycopg2 import tz > [Thu Nov 18 14:26:51 2010] [error] [client 127.0.0.1] ImportError: > cannot import name tz > > > Here is the python script. > > import sys, os > sys.path.append(os.path.dirname(__file__)) > > import psycopg2 > > def application(environ, start_response): > status = '200 OK' > output = 'Hello World!' > > response_headers = [('Content-type', 'text/plain'), > ('Content-Length', str(len(output)))] > start_response(status, response_headers) > > return [output]
Can you change above to use: try: import psycopg2 except: print sys.path raise In other words, catch the exception so you can print the value of sys.path after the failure occurred. This will show any additional directories that egg support may have added for Python egg cache directory. Right now you would be outputting sys.path from before it may have been updated. It may be that cache directory where the build directory exists and the directory may be corrupted or may not be writable to Apache service user and tugs why it is in part failing. Graham > > > > and here is the httpd.conf file. > > > LoadModule wsgi_module modules/mod_wsgi-win32-ap22py27-3.3.so > WSGIScriptAlias / "C:/Projects/SandBox/web/" > <Directory "C:/Projects/SandBox/web"> > AllowOverride None > Options None > Order deny,allow > Allow from all > </Directory> > > > > I check the archive C:\Python27\Lib\site-packages\psycopg2-2.2.2-py2.7- > win32.egg\, i found C:\Python27\Lib\site-packages\psycopg2-2.2.2-py2.7- > win32.egg\psycopg2\tz.py within the archive. > > Thanks. > > -- > You received this message because you are subscribed to the Google Groups > "modwsgi" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/modwsgi?hl=en. > > -- You received this message because you are subscribed to the Google Groups "modwsgi" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/modwsgi?hl=en.
