global name psycopg2 is not defined

1,544 views
Skip to first unread message

salbefe

unread,
Feb 23, 2011, 6:21:16 AM2/23/11
to web2py-users
Hello,

I have read severals posts about this error before posting but no one
solves my problem.

I'm running web2py from sources on a windows xp machine with python
2.6.6. I have downloaded and installed the last binary stable psycopg2
3.2.1 driver for windows and last I have downloaded mod_wsgi-win32-
ap22py26-3.3.so - Apache 2.2 / Python 2.6 from cod.google.com. Apache
2.2 is running ok.

When I run web2py from command line, there is no problem and all works
ok. If I run web2py with apache 2.2 and mod_wsgi is when I get the
error: "global name psycopg2 is not defined"

I have tried to solve the problem uninstalling the psycopg2 binary
driver, and compiling the same from sources. The compilation process
is always ok and puts the .egg file on c:\Python26\Lib\site-packages;
the problem is with the compiled version of psycopg2 when I try to run
web2py from sources it not detects the psycopg2 driver and if I try to
import psycogp2 from the python command line I get an error saying
that "some DLL's were not imported"

I'm running a postgreSQL 9.0 server. Is it possible that I need some
devel postgres libraries??
¿¿Anyone knows how to solve this problem???

Thanks in advance.

Oleg

unread,
Feb 23, 2011, 8:40:08 AM2/23/11
to web...@googlegroups.com
Hallo,

The problem is not in psycopg2 but in your mod_wsgi...
Dont' know  how it works on window exactly, but seems it rely on other python installation.
How did you start Apachi? Do you use cygwin?


salbefe

unread,
Feb 23, 2011, 6:44:23 AM2/23/11
to web2py-users
Sorry, the psycopg2 binary driver is the 2.3.1 and the error I get
when I try to import psycopg2 on the compiled version is:

>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1 in <module>
File "build\bdist.win32\egg\psycopg2\__init__.py", line 69, in
<module>

File "build\bdist.win32\egg\psycopg2\_psycopg2.py", line 7, in
<module>
File "build\bdist.win32\egg\psycopg2\_psycopg2.py", line 6, in
__bootstrap__
ImportError: DLL load failed: No se puede encontrar el modulo
especificado.
Message has been deleted

Oleg

unread,
Feb 24, 2011, 5:12:00 AM2/24/11
to web...@googlegroups.com

salbefe

unread,
Feb 24, 2011, 6:42:26 AM2/24/11
to web2py-users
yes, with these binary version wsgi does not work. I read a post where
someone post a solution:

ImportError: DLL load failed - How to compile psycopg2 to make it
cooperate with mod_wsgi.


1. install mingw
2. download psycopg2
3. setup.py build -c mingw32
4. replace "-lmsvcr90" with "-lmsvcrt" in build link step
5. execute link step again manually
6. setup.py install --skip-build
7. works for me ;-)


The problem for me is how to execute link step again manually or how
to tell distutils to change the msvc runtime library


On 24 feb, 11:12, Oleg <obutov...@googlemail.com> wrote:
> have you triedhttp://www.stickpeople.com/projects/python/win-psycopg/?

Oleg

unread,
Feb 24, 2011, 1:39:02 PM2/24/11
to web...@googlegroups.com
You dont need to compile psycopg2 yourself. The problem you have, most probable, you can not solve in this way. Take a look here, for example:

salbefe

unread,
Feb 25, 2011, 2:36:17 AM2/25/11
to web2py-users
Thank you Oleg,

But it does not work for me. I get always the same error. I have tried
moving the wsgi directory to several places outside the htdocs and
does not work. I get always "global name psycopg2 is not defined".I'm
using the last binary driver from http://www.stickpeople.com. There is
a comment on the link you have posted that says:

"That should have problems as well as when mapping to a directory the
trailing slash on URL where it mounts in WSGIScriptAlias line is
important."

Perhaps that is the key to get it working but I don't unterdand what
it means.



On 24 feb, 19:39, Oleg <obutov...@googlemail.com> wrote:
> You dont need to compile psycopg2 yourself. The problem you have, most
> probable, you can not solve in this way. Take a look here, for example:http://stackoverflow.com/questions/2160256/problem-install-and-run-ps...

salbefe

unread,
Feb 25, 2011, 5:31:46 AM2/25/11
to web2py-users
I have SOLVED IT !!

I have to compile pyscopg2 but now it works !!

1. I added to the windows path variable ...\PostgrSQL\9.0\bin and ...
\PostgrSQL\9.0\lib
2. install mingw
3. download psycopg2
4. setup.py build -c mingw32
5. setup.py install

and now is working without problems. If ...\PostgrSQL\9.0\bin and ...
\PostgrSQL\9.0\lib are not added to the path is were I have the
problem with the "ImportError: DLL load failed2" when I try to import
psycopg2.


On 25 feb, 08:36, salbefe <salb...@gmail.com> wrote:
> Thank you Oleg,
>
> But it does not work for me. I get always the same error. I have tried
> moving the wsgi directory to several places outside the htdocs and
> does not work. I get always "global name psycopg2 is not defined".I'm
> using the last binary driver fromhttp://www.stickpeople.com. There is
Reply all
Reply to author
Forward
0 new messages