Thread: psycopg used in a ASP page fails

psycopg used in a ASP page fails

From
Barend Köbben
Date:
Hi there,

I have the strange case of the same Python code importing psycopg is
failing in an ASP environment while working as stand-alone or CGI
programme:

This is the code:
import psycopg2

This works fine when running in the python IDLE or on the IIS 6.0 server
as a .py CGI script. However, when run as an ASP script (the same code in
between <% %> tags in a .asp file), it fails with this message:

Python ActiveX Scripting Engine error '80020009'
Traceback (most recent call last):
  File "<Script Block >", line 4, in <module>
    import psycopg2
  File "C:\Python27\lib\site-packages\psycopg2\__init__.py", line 65, in
<module>
    from psycopg2 import tz
ImportError: cannot import name tz

/~kobben/testDB/testDB.asp, line 10
import psycopg2


Other Python ASP scripts work fine, including ones that import modules, eg:
<%
import sys
Response.Write(sys.version)

%>


I must admit I have no clue as to why this happens...

Yours,
--
Barend Köbben
ITC - University of Twente, Faculty of Geo-Information
Science and Earth Observation
PO Box 217, 7500AE Enschede (The Netherlands)



Faculty of Geo-Information Science and Earth Observation (ITC)
University of Twente
Chamber of Commerce: 501305360000

E-mail disclaimer
The information in this e-mail, including any attachments, is intended for the addressee only. If you are not the
intendedrecipient, you are hereby notified that any disclosure, copying, distribution or action in relation to the
contentof this information is strictly prohibited. If you have received this e-mail by mistake, please delete the
messageand any attachment and inform the sender by return e-mail. ITC accepts no liability for any error or omission in
themessage content or for damage of any kind that may arise as a result of e-mail transmission. 

Re: psycopg used in a ASP page fails

From
Daniele Varrazzo
Date:
2011/2/15 Barend Köbben <kobben@itc.nl>:
> Hi there,
>
> I have the strange case of the same Python code importing psycopg is
> failing in an ASP environment while working as stand-alone or CGI
> programme:
>
> This is the code:
> import psycopg2
>
> This works fine when running in the python IDLE or on the IIS 6.0 server
> as a .py CGI script. However, when run as an ASP script (the same code in
> between <% %> tags in a .asp file), it fails with this message:
>
> Python ActiveX Scripting Engine error '80020009'
> Traceback (most recent call last):
>  File "<Script Block >", line 4, in <module>
>    import psycopg2
>  File "C:\Python27\lib\site-packages\psycopg2\__init__.py", line 65, in
> <module>
>    from psycopg2 import tz
> ImportError: cannot import name tz

May this be the same problem Jason is currently addressing. Could you
please test with both psycopg 2.4 beta2 and 2.3.2 and report the
result?

I've also found this:
<http://stackoverflow.com/questions/4212240/importerror-cannot-import-name-tz-psycopg2>.
Well, that sucks! But I think it may be your problem. Have you
installed psycopg using easy_install?

I wonder if it can be solved by marking psycopg2 not zip-safe (when
psycopg2 is installed via easy_install, I see the log "zip_safe flag
not set; analyzing archive contents...", which makes me think there is
an option). Uhm... no. Reading
<http://packages.python.org/distribute/setuptools.html#setting-the-zip-safe-flag>
looks like psycopg is considered unsafe as it contains a C extension.
So I'm afraid it will keep on sucking :( While at it, I'm also
noticing that "easy_install psycopg2" is installing 2.4 beta2 even if
2.3.2 is the last version listed on PyPI and the beta is nowhere. At
which, I give up thinking easy_install is any good at all.

-- Daniele

Re: psycopg used in a ASP page fails

From
Daniele Varrazzo
Date:
2011/2/15 Daniele Varrazzo <daniele.varrazzo@gmail.com>:

> I've also found this:
> <http://stackoverflow.com/questions/4212240/importerror-cannot-import-name-tz-psycopg2>.
> Well, that sucks! But I think it may be your problem. Have you
> installed psycopg using easy_install?

Added a FAQ for this mess. A better way to fix the issue would be
great, but I think it's an easy_install one.

http://initd.org/psycopg/docs/faq.html#problems-compiling-and-deploying-psycopg2

-- Daniele

Re: psycopg used in a ASP page fails

From
Barend Köbben
Date:
Hi Daniele,

> Well, that sucks! But I think it may be your problem. Have
> you installed psycopg using easy_install?

No. It's a Win32 install on a Windows Server 2003 box with IIS 6.0 (hence
the ASP). Your fix suggests that also ASP might have the problem that the
ASP engine has no write permission on a path, the one you mention to be
"PYTHON_EGG_INSTALL". Is there any way to find out where this (or its
equivalent) would be on Windows? Can't find it in windows Environment
variables and really don't know here else to look :-((

Yours,

--
Barend Köbben
ITC - University of Twente, Faculty of Geo-Information
Science and Earth Observation
PO Box 217, 7500AE Enschede (The Netherlands)





On 15-02-11 14:10, "Daniele Varrazzo" <daniele.varrazzo@gmail.com> wrote:

>2011/2/15 Daniele Varrazzo <daniele.varrazzo@gmail.com>:
>
>> I've also found this:
>>
>><http://stackoverflow.com/questions/4212240/importerror-cannot-import-nam
>>e-tz-psycopg2>.
>> Well, that sucks! But I think it may be your problem. Have you
>> installed psycopg using easy_install?
>
>Added a FAQ for this mess. A better way to fix the issue would be
>great, but I think it's an easy_install one.
>
>http://initd.org/psycopg/docs/faq.html#problems-compiling-and-deploying-ps
>ycopg2
>
>-- Daniele


Faculty of Geo-Information Science and Earth Observation (ITC)
University of Twente
Chamber of Commerce: 501305360000

E-mail disclaimer
The information in this e-mail, including any attachments, is intended for the addressee only. If you are not the
intendedrecipient, you are hereby notified that any disclosure, copying, distribution or action in relation to the
contentof this information is strictly prohibited. If you have received this e-mail by mistake, please delete the
messageand any attachment and inform the sender by return e-mail. ITC accepts no liability for any error or omission in
themessage content or for damage of any kind that may arise as a result of e-mail transmission. 

Re: psycopg used in a ASP page fails

From
Daniele Varrazzo
Date:
2011/2/16 Barend Köbben <kobben@itc.nl>:
> Hi Daniele,
>
>> Well, that sucks! But I think it may be your problem. Have
>> you installed psycopg using easy_install?
>
> No. It's a Win32 install on a Windows Server 2003 box with IIS 6.0 (hence
> the ASP). Your fix suggests that also ASP might have the problem that the
> ASP engine has no write permission on a path, the one you mention to be
> "PYTHON_EGG_INSTALL". Is there any way to find out where this (or its
> equivalent) would be on Windows? Can't find it in windows Environment
> variables and really don't know here else to look :-((

If you haven't used easy install, the above issue should not apply: it
seems only related to egg packages.

I can only suggest you to try the psycopg 2.4 beta2 installation
provided by Jason, where he has addressed dll compatibility problems.
I personally don't have recent experience in debugging dll problems on
windows.

Please report which version of psycopg and python you are using in
your message, thanks. It seems that things got more complex starting
from python 2.6. Consider the option of compiling psycopg with mingw
as explained in
<http://psycopg.lighthouseapp.com/projects/62710/tickets/20>.

-- Daniele

Re: psycopg used in a ASP page fails

From
Jason Erickson
Date:
On Wed, 16 Feb 2011, Daniele Varrazzo wrote:

> 2011/2/16 Barend K�bben <kobben@itc.nl>:
>> Hi Daniele,
>>
>>> Well, that sucks! But I think it may be your problem. Have
>>> you installed psycopg using easy_install?
>>
>> No. It's a Win32 install on a Windows Server 2003 box with IIS 6.0 (hence
>> the ASP). Your fix suggests that also ASP might have the problem that the
>> ASP engine has no write permission on a path, the one you mention to be
>> "PYTHON_EGG_INSTALL". Is there any way to find out where this (or its
>> equivalent) would be on Windows? Can't find it in windows Environment
>> variables and really don't know here else to look :-((
>
> If you haven't used easy install, the above issue should not apply: it
> seems only related to egg packages.
>
> I can only suggest you to try the psycopg 2.4 beta2 installation
> provided by Jason, where he has addressed dll compatibility problems.
> I personally don't have recent experience in debugging dll problems on
> windows.
>
> Please report which version of psycopg and python you are using in
> your message, thanks. It seems that things got more complex starting
> from python 2.6. Consider the option of compiling psycopg with mingw
> as explained in
> <http://psycopg.lighthouseapp.com/projects/62710/tickets/20>.
>
> -- Daniele


Instead of 'import psycopg2', does the following code work when run as an
ASP script?:
----------------------------------------------------------
from psycopg2._psycopg import __version__
----------------------------------------------------------

For craziness sakes, does the following code work in ASP land?:
----------------------------------------------------------
from psycopg2 import tz
----------------------------------------------------------


Also, verify that the following file exist (which it should, since it
works other ways):
     %PYTHON_INSTALL_DIR%\Lib\site-packages\psycopg2\tz.py

Also, can you verify that there is not a psycopg directory or psycopg.py
file in that same directory?
     %PYTHON_INSTALL_DIR%\Lib\site-packages\psycopg2


You didn't mention what version of python you are using?


With an ASP script, can you also try this code (I'm assuming that
Response.Write is similar to print, change otherwise):
----------------------------------------------------------
import sys
Reponse.Write(sys.path)
----------------------------------------------------------
This code will print the 'search' path for python modules.  This search
path should be the same as when you run the python interpreter by hand,
tho maybe ASP is adding something to it??  Verify that they are the same.


Can you also verify that it is finding the correct 'module' with the
following asp code:
----------------------------------------------------------
import imp
f, filename, description = imp.find_module('psycopg2')
Response.Write('psycopg2 file location: '+filename)
----------------------------------------------------------
What it prints should be the path to the psycopg2 install directory.
Verify that it is pointing to the correct directory where you installed
psycopg2, and that the file tz.py is in that directory.



This is interesting because of where it fails.  First off, it is finding a
psycopg2 directory, as it is importing (or trying to import) __init__.
Second, it is not failing on loading the dll, but failing on a step before
loading the dll, where it is loading a module inside the psycopg2 package
(tz).  It is almost as if the sys.path is different between ASP land and
normal land, causing the issue.

It is possible that it is similar to the manifest issue that we see with
modwsgi, but I'm thinking not.  Please try the beta version at:
     http://www.stickpeople.com/projects/python/win-psycopg/devel/
as well.

-jason

Re: psycopg used in a ASP page fails

From
Daniele Varrazzo
Date:
On Wed, Feb 16, 2011 at 8:37 PM, Jason Erickson
<jerickso@stickpeople.com> wrote:

> Instead of 'import psycopg2', does the following code work when run as an
> ASP script?:
> ---------------------------------------------------------- from
> psycopg2._psycopg import __version__
> ----------------------------------------------------------
>
> For craziness sakes, does the following code work in ASP land?:
> ---------------------------------------------------------- from psycopg2
> import tz ----------------------------------------------------------
>
>
> Also, verify that the following file exist (which it should, since it works
> other ways):
>        %PYTHON_INSTALL_DIR%\Lib\site-packages\psycopg2\tz.py
>
> Also, can you verify that there is not a psycopg directory or psycopg.py
> file in that same directory?
>        %PYTHON_INSTALL_DIR%\Lib\site-packages\psycopg2
>
>
> You didn't mention what version of python you are using?
>
>
> With an ASP script, can you also try this code (I'm assuming that
> Response.Write is similar to print, change otherwise):
> ----------------------------------------------------------
> import sys Reponse.Write(sys.path)
> ----------------------------------------------------------
> This code will print the 'search' path for python modules.  This search path
> should be the same as when you run the python interpreter by hand, tho maybe
> ASP is adding something to it??  Verify that they are the same.
>
>
> Can you also verify that it is finding the correct 'module' with the
> following asp code:
> ----------------------------------------------------------
> import imp
> f, filename, description = imp.find_module('psycopg2')
> Response.Write('psycopg2 file location: '+filename)
> ----------------------------------------------------------
> What it prints should be the path to the psycopg2 install directory. Verify
> that it is pointing to the correct directory where you installed psycopg2,
> and that the file tz.py is in that directory.
>
>
>
> This is interesting because of where it fails.  First off, it is finding a
> psycopg2 directory, as it is importing (or trying to import) __init__.
> Second, it is not failing on loading the dll, but failing on a step before
> loading the dll, where it is loading a module inside the psycopg2 package
> (tz).  It is almost as if the sys.path is different between ASP land and
> normal land, causing the issue.
>
> It is possible that it is similar to the manifest issue that we see with
> modwsgi, but I'm thinking not.  Please try the beta version at:
>        http://www.stickpeople.com/projects/python/win-psycopg/devel/
> as well.

Hi,

I've just found how to reproduce the the "cannot find tz". I think
it's still related to the failed dll import, but it happens _on the
second import_ of psycopg.

Artificially making the _psycopg import failing:

    $ sudo mv -vi /usr/lib/{,-}libpq.so.5

The first import gives a clean error message:

    >>> import psycopg2
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/piro/dev/psycopg2/dist/tmp/psycopg2/__init__.py",
line 69, in <module>
        from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
    ImportError: libpq.so.5: cannot open shared object file: No such
file or directory

But the second gives:

    >>> import psycopg2
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/piro/dev/psycopg2/dist/tmp/psycopg2/__init__.py",
line 65, in <module>
        from psycopg2 import tz
    ImportError: cannot import name tz

So probably the first traceback is swallowed away somewhere.

The reason is in the order of the imports in psycopg2/__init__.py:
after the first import error what is imported in the system is:

    >>> print "\n".join(filter(re.compile("psyco").search,
sorted(sys.modules.keys())))
    psycopg2.datetime
    psycopg2.decimal
    psycopg2.psycopg2
    psycopg2.sys
    psycopg2.time
    psycopg2.tz
    psycopg2.warnings

it seems an inconsistent status with "psycopg2.tz" was loaded but
"psycopg2" is not available. Taking the care to have _psycopg imported
before the other submodules:

    --- __init__.py    2011-02-16 23:02:27.000000000 +0000
    +++ __init__.py.new    2011-02-17 09:35:41.752056278 +0000
    @@ -62,8 +62,6 @@
                 RuntimeWarning)
     del sys, warnings

    -from psycopg2 import tz
    -
     # Import the DBAPI-2.0 stuff into top-level module.

     from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
    @@ -78,6 +76,8 @@
     from psycopg2._psycopg import connect, apilevel, threadsafety, paramstyle
     from psycopg2._psycopg import __version__

    +from psycopg2 import tz
    +
     # Register default adapters.

     import psycopg2.extensions as _ext

we can get the consistent import error about the failed _psycopg import.

Barend, if you could change the psycopg2/__init__.py as shown above
and repeat your test we may get the real reason of the failed import.
Please don't forget to include the Python and psycopg versions you are
using, and to make a test with the 2.4 beta2 too. Thank you.

-- Daniele

Re: psycopg used in a ASP page fails

From
Barend Köbben
Date:
Hi there,

Thanks for taking all the trouble. I will make those changes in
__init__.py and test in different versions, but that will probably have to
wait until Friday, I have deadlines toi make on other stuff today. I'll
let you know later...

Bye,
--
Barend Köbben
ITC - University of Twente, Faculty of Geo-Information
Science and Earth Observation
PO Box 217, 7500AE Enschede (The Netherlands)


On 17-02-11 10:46, "Daniele Varrazzo" <daniele.varrazzo@gmail.com> wrote:

>On Wed, Feb 16, 2011 at 8:37 PM, Jason Erickson
><jerickso@stickpeople.com> wrote:
>
>> Instead of 'import psycopg2', does the following code work when run as
>>an
>> ASP script?:
>> ---------------------------------------------------------- from
>> psycopg2._psycopg import __version__
>> ----------------------------------------------------------
>>
>> For craziness sakes, does the following code work in ASP land?:
>> ---------------------------------------------------------- from psycopg2
>> import tz ----------------------------------------------------------
>>
>>
>> Also, verify that the following file exist (which it should, since it
>>works
>> other ways):
>>        %PYTHON_INSTALL_DIR%\Lib\site-packages\psycopg2\tz.py
>>
>> Also, can you verify that there is not a psycopg directory or psycopg.py
>> file in that same directory?
>>        %PYTHON_INSTALL_DIR%\Lib\site-packages\psycopg2
>>
>>
>> You didn't mention what version of python you are using?
>>
>>
>> With an ASP script, can you also try this code (I'm assuming that
>> Response.Write is similar to print, change otherwise):
>> ----------------------------------------------------------
>> import sys Reponse.Write(sys.path)
>> ----------------------------------------------------------
>> This code will print the 'search' path for python modules.  This search
>>path
>> should be the same as when you run the python interpreter by hand, tho
>>maybe
>> ASP is adding something to it??  Verify that they are the same.
>>
>>
>> Can you also verify that it is finding the correct 'module' with the
>> following asp code:
>> ----------------------------------------------------------
>> import imp
>> f, filename, description = imp.find_module('psycopg2')
>> Response.Write('psycopg2 file location: '+filename)
>> ----------------------------------------------------------
>> What it prints should be the path to the psycopg2 install directory.
>>Verify
>> that it is pointing to the correct directory where you installed
>>psycopg2,
>> and that the file tz.py is in that directory.
>>
>>
>>
>> This is interesting because of where it fails.  First off, it is
>>finding a
>> psycopg2 directory, as it is importing (or trying to import) __init__.
>> Second, it is not failing on loading the dll, but failing on a step
>>before
>> loading the dll, where it is loading a module inside the psycopg2
>>package
>> (tz).  It is almost as if the sys.path is different between ASP land and
>> normal land, causing the issue.
>>
>> It is possible that it is similar to the manifest issue that we see with
>> modwsgi, but I'm thinking not.  Please try the beta version at:
>>        http://www.stickpeople.com/projects/python/win-psycopg/devel/
>> as well.
>
>Hi,
>
>I've just found how to reproduce the the "cannot find tz". I think
>it's still related to the failed dll import, but it happens _on the
>second import_ of psycopg.
>
>Artificially making the _psycopg import failing:
>
>    $ sudo mv -vi /usr/lib/{,-}libpq.so.5
>
>The first import gives a clean error message:
>
>    >>> import psycopg2
>    Traceback (most recent call last):
>      File "<stdin>", line 1, in <module>
>      File "/home/piro/dev/psycopg2/dist/tmp/psycopg2/__init__.py",
>line 69, in <module>
>        from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME,
>ROWID
>    ImportError: libpq.so.5: cannot open shared object file: No such
>file or directory
>
>But the second gives:
>
>    >>> import psycopg2
>    Traceback (most recent call last):
>      File "<stdin>", line 1, in <module>
>      File "/home/piro/dev/psycopg2/dist/tmp/psycopg2/__init__.py",
>line 65, in <module>
>        from psycopg2 import tz
>    ImportError: cannot import name tz
>
>So probably the first traceback is swallowed away somewhere.
>
>The reason is in the order of the imports in psycopg2/__init__.py:
>after the first import error what is imported in the system is:
>
>    >>> print "\n".join(filter(re.compile("psyco").search,
>sorted(sys.modules.keys())))
>    psycopg2.datetime
>    psycopg2.decimal
>    psycopg2.psycopg2
>    psycopg2.sys
>    psycopg2.time
>    psycopg2.tz
>    psycopg2.warnings
>
>it seems an inconsistent status with "psycopg2.tz" was loaded but
>"psycopg2" is not available. Taking the care to have _psycopg imported
>before the other submodules:
>
>    --- __init__.py    2011-02-16 23:02:27.000000000 +0000
>    +++ __init__.py.new    2011-02-17 09:35:41.752056278 +0000
>    @@ -62,8 +62,6 @@
>                 RuntimeWarning)
>     del sys, warnings
>
>    -from psycopg2 import tz
>    -
>     # Import the DBAPI-2.0 stuff into top-level module.
>
>     from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
>    @@ -78,6 +76,8 @@
>     from psycopg2._psycopg import connect, apilevel, threadsafety,
>paramstyle
>     from psycopg2._psycopg import __version__
>
>    +from psycopg2 import tz
>    +
>     # Register default adapters.
>
>     import psycopg2.extensions as _ext
>
>we can get the consistent import error about the failed _psycopg import.
>
>Barend, if you could change the psycopg2/__init__.py as shown above
>and repeat your test we may get the real reason of the failed import.
>Please don't forget to include the Python and psycopg versions you are
>using, and to make a test with the 2.4 beta2 too. Thank you.
>
>-- Daniele


Faculty of Geo-Information Science and Earth Observation (ITC)
University of Twente
Chamber of Commerce: 501305360000

E-mail disclaimer
The information in this e-mail, including any attachments, is intended for the addressee only. If you are not the
intendedrecipient, you are hereby notified that any disclosure, copying, distribution or action in relation to the
contentof this information is strictly prohibited. If you have received this e-mail by mistake, please delete the
messageand any attachment and inform the sender by return e-mail. ITC accepts no liability for any error or omission in
themessage content or for damage of any kind that may arise as a result of e-mail transmission. 

Re: psycopg used in a ASP page fails

From
Barend Köbben
Date:
Hello there,

Sorry it took me a long time to come back on this, priorities always
shifting :-(

With pleasure I can now report that updating to psycoPG2 2.4 solved the
problem with import psycopPG2 in an  ASP page.

Thanks for all the help!

--
Barend Köbben
ITC - University of Twente, Faculty of Geo-Information
Science and Earth Observation
PO Box 217, 7500AE Enschede (The Netherlands)
+31-(0)53 4874 253




On 17-02-11 11:05, "Barend Köbben" <kobben@itc.nl> wrote:

>Hi there,
>
>Thanks for taking all the trouble. I will make those changes in
>__init__.py and test in different versions, but that will probably have to
>wait until Friday, I have deadlines toi make on other stuff today. I'll
>let you know later...
>
>Bye,
>--
>Barend Köbben
>ITC - University of Twente, Faculty of Geo-Information
>Science and Earth Observation
>PO Box 217, 7500AE Enschede (The Netherlands)
>
>
>On 17-02-11 10:46, "Daniele Varrazzo" <daniele.varrazzo@gmail.com> wrote:
>
>>On Wed, Feb 16, 2011 at 8:37 PM, Jason Erickson
>><jerickso@stickpeople.com> wrote:
>>
>>> Instead of 'import psycopg2', does the following code work when run as
>>>an
>>> ASP script?:
>>> ---------------------------------------------------------- from
>>> psycopg2._psycopg import __version__
>>> ----------------------------------------------------------
>>>
>>> For craziness sakes, does the following code work in ASP land?:
>>> ---------------------------------------------------------- from
>>>psycopg2
>>> import tz ----------------------------------------------------------
>>>
>>>
>>> Also, verify that the following file exist (which it should, since it
>>>works
>>> other ways):
>>>        %PYTHON_INSTALL_DIR%\Lib\site-packages\psycopg2\tz.py
>>>
>>> Also, can you verify that there is not a psycopg directory or
>>>psycopg.py
>>> file in that same directory?
>>>        %PYTHON_INSTALL_DIR%\Lib\site-packages\psycopg2
>>>
>>>
>>> You didn't mention what version of python you are using?
>>>
>>>
>>> With an ASP script, can you also try this code (I'm assuming that
>>> Response.Write is similar to print, change otherwise):
>>> ----------------------------------------------------------
>>> import sys Reponse.Write(sys.path)
>>> ----------------------------------------------------------
>>> This code will print the 'search' path for python modules.  This search
>>>path
>>> should be the same as when you run the python interpreter by hand, tho
>>>maybe
>>> ASP is adding something to it??  Verify that they are the same.
>>>
>>>
>>> Can you also verify that it is finding the correct 'module' with the
>>> following asp code:
>>> ----------------------------------------------------------
>>> import imp
>>> f, filename, description = imp.find_module('psycopg2')
>>> Response.Write('psycopg2 file location: '+filename)
>>> ----------------------------------------------------------
>>> What it prints should be the path to the psycopg2 install directory.
>>>Verify
>>> that it is pointing to the correct directory where you installed
>>>psycopg2,
>>> and that the file tz.py is in that directory.
>>>
>>>
>>>
>>> This is interesting because of where it fails.  First off, it is
>>>finding a
>>> psycopg2 directory, as it is importing (or trying to import) __init__.
>>> Second, it is not failing on loading the dll, but failing on a step
>>>before
>>> loading the dll, where it is loading a module inside the psycopg2
>>>package
>>> (tz).  It is almost as if the sys.path is different between ASP land
>>>and
>>> normal land, causing the issue.
>>>
>>> It is possible that it is similar to the manifest issue that we see
>>>with
>>> modwsgi, but I'm thinking not.  Please try the beta version at:
>>>        http://www.stickpeople.com/projects/python/win-psycopg/devel/
>>> as well.
>>
>>Hi,
>>
>>I've just found how to reproduce the the "cannot find tz". I think
>>it's still related to the failed dll import, but it happens _on the
>>second import_ of psycopg.
>>
>>Artificially making the _psycopg import failing:
>>
>>    $ sudo mv -vi /usr/lib/{,-}libpq.so.5
>>
>>The first import gives a clean error message:
>>
>>    >>> import psycopg2
>>    Traceback (most recent call last):
>>      File "<stdin>", line 1, in <module>
>>      File "/home/piro/dev/psycopg2/dist/tmp/psycopg2/__init__.py",
>>line 69, in <module>
>>        from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME,
>>ROWID
>>    ImportError: libpq.so.5: cannot open shared object file: No such
>>file or directory
>>
>>But the second gives:
>>
>>    >>> import psycopg2
>>    Traceback (most recent call last):
>>      File "<stdin>", line 1, in <module>
>>      File "/home/piro/dev/psycopg2/dist/tmp/psycopg2/__init__.py",
>>line 65, in <module>
>>        from psycopg2 import tz
>>    ImportError: cannot import name tz
>>
>>So probably the first traceback is swallowed away somewhere.
>>
>>The reason is in the order of the imports in psycopg2/__init__.py:
>>after the first import error what is imported in the system is:
>>
>>    >>> print "\n".join(filter(re.compile("psyco").search,
>>sorted(sys.modules.keys())))
>>    psycopg2.datetime
>>    psycopg2.decimal
>>    psycopg2.psycopg2
>>    psycopg2.sys
>>    psycopg2.time
>>    psycopg2.tz
>>    psycopg2.warnings
>>
>>it seems an inconsistent status with "psycopg2.tz" was loaded but
>>"psycopg2" is not available. Taking the care to have _psycopg imported
>>before the other submodules:
>>
>>    --- __init__.py    2011-02-16 23:02:27.000000000 +0000
>>    +++ __init__.py.new    2011-02-17 09:35:41.752056278 +0000
>>    @@ -62,8 +62,6 @@
>>                 RuntimeWarning)
>>     del sys, warnings
>>
>>    -from psycopg2 import tz
>>    -
>>     # Import the DBAPI-2.0 stuff into top-level module.
>>
>>     from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME,
>>ROWID
>>    @@ -78,6 +76,8 @@
>>     from psycopg2._psycopg import connect, apilevel, threadsafety,
>>paramstyle
>>     from psycopg2._psycopg import __version__
>>
>>    +from psycopg2 import tz
>>    +
>>     # Register default adapters.
>>
>>     import psycopg2.extensions as _ext
>>
>>we can get the consistent import error about the failed _psycopg import.
>>
>>Barend, if you could change the psycopg2/__init__.py as shown above
>>and repeat your test we may get the real reason of the failed import.
>>Please don't forget to include the Python and psycopg versions you are
>>using, and to make a test with the 2.4 beta2 too. Thank you.
>>
>>-- Daniele
>
>
>Faculty of Geo-Information Science and Earth Observation (ITC)
>University of Twente
>Chamber of Commerce: 501305360000
>
>E-mail disclaimer
>The information in this e-mail, including any attachments, is intended
>for the addressee only. If you are not the intended recipient, you are
>hereby notified that any disclosure, copying, distribution or action in
>relation to the content of this information is strictly prohibited. If
>you have received this e-mail by mistake, please delete the message and
>any attachment and inform the sender by return e-mail. ITC accepts no
>liability for any error or omission in the message content or for damage
>of any kind that may arise as a result of e-mail transmission.
>
>--
>Sent via psycopg mailing list (psycopg@postgresql.org)
>To make changes to your subscription:
>http://www.postgresql.org/mailpref/psycopg


Faculty of Geo-Information Science and Earth Observation (ITC)
University of Twente
Chamber of Commerce: 501305360000

E-mail disclaimer
The information in this e-mail, including any attachments, is intended for the addressee only. If you are not the
intendedrecipient, you are hereby notified that any disclosure, copying, distribution or action in relation to the
contentof this information is strictly prohibited. If you have received this e-mail by mistake, please delete the
messageand any attachment and inform the sender by return e-mail. ITC accepts no liability for any error or omission in
themessage content or for damage of any kind that may arise as a result of e-mail transmission.