472,342 Members | 1,731 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

zlib + Windows 32 service problem (ImportError)

Sorry, I realized that the import zlib was not executed from my
(working) service.
So here is the question: why can't I use zlib from a win32 service? Is
there any way to make it working?
-------------
Python could not import the service's module
File "T:\Python\Projects\NamedConnector\Service.py" , line 17, in ?
from Processor import *
File "c:\Python\Projects\NamedConnector\Processor.p y", line 35, in ?
from mess import MessageSocket
File "T:\Python\Lib\mess\MessageSocket.py", line 31, in ?
import zlib
exceptions.ImportError: dynamic module does not define init function
(initzlib)
-------------


Aug 15 '05 #1
6 3310
"Laszlo Zsolt Nagy" <ga*****@geochemsource.com> schrieb im Newsbeitrag
news:ma***************************************@pyt hon.org...
| Sorry, I realized that the import zlib was not executed from my
| (working) service.
| So here is the question: why can't I use zlib from a win32 service? Is
| there any way to make it working?
|
| >-------------
| >Python could not import the service's module
| > File "T:\Python\Projects\NamedConnector\Service.py" , line 17, in ?
| > from Processor import *
| > File "c:\Python\Projects\NamedConnector\Processor.p y", line 35, in ?
| > from mess import MessageSocket
| > File "T:\Python\Lib\mess\MessageSocket.py", line 31, in ?
| > import zlib
| >exceptions.ImportError: dynamic module does not define init function
| >(initzlib)
| >-------------
|
|
|
I had a similar problem where a zlib.dll that is *not a Python extension* is
in sys.path *before* zlib.pyd. Python will try to import this zlib.dll and
find the dll doesn't export a initzlib:
for more info see
http://mail.python.org/pipermail/pyt...ad.html#248107

HTH,

Vincent Wehren


Aug 15 '05 #2
vincent wehren wrote:
"Laszlo Zsolt Nagy" <ga*****@geochemsource.com> schrieb im Newsbeitrag
news:ma***************************************@py thon.org...
| Sorry, I realized that the import zlib was not executed from my
| (working) service.
| So here is the question: why can't I use zlib from a win32 service? Is
| there any way to make it working?
|
| >-------------
| >Python could not import the service's module
| > File "T:\Python\Projects\NamedConnector\Service.py" , line 17, in ?
| > from Processor import *
| > File "c:\Python\Projects\NamedConnector\Processor.p y", line 35, in ?
| > from mess import MessageSocket
| > File "T:\Python\Lib\mess\MessageSocket.py", line 31, in ?
| > import zlib
| >exceptions.ImportError: dynamic module does not define init function
| >(initzlib)
| >-------------
|
|
|
I had a similar problem where a zlib.dll that is *not a Python extension* is
in sys.path *before* zlib.pyd. Python will try to import this zlib.dll and
find the dll doesn't export a initzlib:
for more info see
http://mail.python.org/pipermail/pyt...ad.html#248107

Thanks. I set my system environment variable 'PATH' to this:

C:\Python24;C:\Python24\DLLs;c:\Python24\Lib\site-packages\win32;c:\oracle\product\10.1.0\db_1\bin;c :\oracle\product\10.1.0\db_1\jre\1.4.2\bin\client; c:\oracle\product\10.1.0\db_1\jre\1.4.2\bin;%Syste mRoot%\system32;%SystemRoot%;%SystemRoot%\System32 \Wbem;C:\Program
Files\Common Files\GTK\2.0\bin

Then I restarted my computer. It is still missing initzlib. :-(
Please note that I can run the same program as an application, logged in
as the same user.

Les

Aug 16 '05 #3

"Laszlo Zsolt Nagy" <ga*****@geochemsource.com> schrieb im Newsbeitrag
news:ma***************************************@pyt hon.org...
| vincent wehren wrote:
|
| >"Laszlo Zsolt Nagy" <ga*****@geochemsource.com> schrieb im Newsbeitrag
| >news:ma***************************************@py thon.org...
| >| Sorry, I realized that the import zlib was not executed from my
| >| (working) service.
| >| So here is the question: why can't I use zlib from a win32 service? Is
| >| there any way to make it working?
| >|
| >| >-------------
| >| >Python could not import the service's module
| >| > File "T:\Python\Projects\NamedConnector\Service.py" , line 17, in ?
| >| > from Processor import *
| >| > File "c:\Python\Projects\NamedConnector\Processor.p y", line 35, in ?
| >| > from mess import MessageSocket
| >| > File "T:\Python\Lib\mess\MessageSocket.py", line 31, in ?
| >| > import zlib
| >| >exceptions.ImportError: dynamic module does not define init function
| >| >(initzlib)
| >| >-------------
| >|
| >|
| >|
| >I had a similar problem where a zlib.dll that is *not a Python extension*
is
| >in sys.path *before* zlib.pyd. Python will try to import this zlib.dll
and
| >find the dll doesn't export a initzlib:
| >for more info see
|
http://mail.python.org/pipermail/pyt...ad.html#248107

| >
| >
| Thanks. I set my system environment variable 'PATH' to this:
|
|
C:\Python24;C:\Python24\DLLs;c:\Python24\Lib\site-packages\win32;c:\oracle\product\10.1.0\db_1\bin;c :\oracle\product\10.1.0\db_1\jre\1.4.2\bin\client; c:\oracle\product\10.1.0\db_1\jre\1.4.2\bin;%Syste mRoot%\system32;%SystemRoot%;%SystemRoot%\System32 \Wbem;C:\Program
| Files\Common Files\GTK\2.0\bin
|
| Then I restarted my computer. It is still missing initzlib. :-(
| Please note that I can run the same program as an application, logged in
| as the same user.
|
| Les

Changing the Windows dll search path doesn't make any difference. It is
sys.path (Python's search path) that's causing you the headache. Please see
the mentioned thread for proposed solutions.
Regards,
--

Vincent Wehren
Aug 16 '05 #4
|
|
C:\Python24;C:\Python24\DLLs;c:\Python24\Lib\si te-packages\win32;c:\oracle\product\10.1.0\db_1\bin;c :\oracle\product\10.1.0\db_1\jre\1.4.2\bin\client; c:\oracle\product\10.1.0\db_1\jre\1.4.2\bin;%Syste mRoot%\system32;%SystemRoot%;%SystemRoot%\System32 \Wbem;C:\Program
| Files\Common Files\GTK\2.0\bin
|
| Then I restarted my computer. It is still missing initzlib. :-(
| Please note that I can run the same program as an application, logged in
| as the same user.
|
| Les

Changing the Windows dll search path doesn't make any difference. It is
sys.path (Python's search path) that's causing you the headache. Please see
the mentioned thread for proposed solutions.

Great. I could make my service working with this snippet:

import sys
sys.path.insert(0,r'C:\Python24\DLLs')

But this is very ugly. Primarily, I do not want to use absolute path
names in a this program. I want to use the same code on different
computers and operating systems, but this code is not portable.
Secondly, I do not understand why sys.path is different when I start
python interactively. I believe that sys.path should be the same when
starting the program as a service. The only difference between the
application and the service is that the 'main' program of the service
imports some additional modules. See them below.

iT:\Python\Projects\NamedConnector>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
import sys

s1 = str(sys.path)

import win32serviceutil, win32service
import pywintypes, win32con, winerror
from win32event import *
from win32file import *
from win32pipe import *
from win32api import *
from ntsecuritycon import *
s2 = str(sys.path)

print s1 == s2

True

I cannot distribute my service until I make it independent of the python
installation directory.

Why sys.path is different when starting the code as a windows service?
How can I make this code portable?

By the way, you have been a great help. Thank you very much. I can now
continue working. :-)

Les
Aug 17 '05 #5
Laszlo Zsolt Nagy wrote:
|
|
C:\Python24;C:\Python24\DLLs;c:\Python24\Lib\site-packages\win32;c:\oracle\product\10.1.0\db_1\bin;c :\oracle\product\10.1.0\db_1\jre\1.4.2\bin\client; c:\oracle\product\10.1.0\db_1\jre\1.4.2\bin;%Syste mRoot%\system32;%SystemRoot%;%SystemRoot%\System32 \Wbem;C:\Program

| Files\Common Files\GTK\2.0\bin
|
| Then I restarted my computer. It is still missing initzlib. :-(
| Please note that I can run the same program as an application,
logged in
| as the same user.
|
| Les

Changing the Windows dll search path doesn't make any difference. It
is sys.path (Python's search path) that's causing you the headache.
Please see the mentioned thread for proposed solutions.

Great. I could make my service working with this snippet:

import sys
sys.path.insert(0,r'C:\Python24\DLLs')

But this is very ugly. Primarily, I do not want to use absolute path
names in a this program. I want to use the same code on different
computers and operating systems, but this code is not portable.


Try this (or something like it):
if sys.platform == "win32":
sys.path.insert(0, sys.exec_prefix + r'\DLLs')

Secondly, I do not understand why sys.path is different when I start
python interactively. I believe that sys.path should be the same when
starting the program as a service. The only difference between the
application and the service is that the 'main' program of the service
imports some additional modules. See them below.

iT:\Python\Projects\NamedConnector>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>>
>>> s1 = str(sys.path) Add this:
print os.getcwd() # see below for why >>>
>>> import win32serviceutil, win32service
>>> import pywintypes, win32con, winerror
>>> from win32event import *
>>> from win32file import *
>>> from win32pipe import *
>>> from win32api import *
>>> from ntsecuritycon import *
>>>
>>>
>>> s2 = str(sys.path)
Why do you think str() is needed here?
>>>
>>> print s1 == s2
True


Add in here:

print sys.path
print os.getcwd() # see below for why

I cannot distribute my service until I make it independent of the python
installation directory.

Why sys.path is different when starting the code as a windows service?


Possibly because sys.path can start with '' which is interpreted as the
current directory. Perhaps when the code is started as a windows service
[I know nothing about windows services], the current directory is set to
%windir%\system32 (where lots of DLLs hang out), and if there is a
zlib.dll there, it will get picked up first. Try printing the current
directory (see above).

Setting the PYTHONVERBOSE environment variable may assist in showing
where modules are being loaded from.

HTH,
John
Aug 17 '05 #6
Why do you think str() is needed here?

Because I'm not sure if sys.path was overwritten or changed. Some bad
modules could overwrite sys.path with another list. I know I'm paranoid. :-)
Possibly because sys.path can start with '' which is interpreted as the
current directory. Perhaps when the code is started as a windows service
[I know nothing about windows services], the current directory is set to
%windir%\system32 (where lots of DLLs hang out), and if there is a
zlib.dll there, it will get picked up first. Try printing the current
directory (see above).

Okay, I did so. I wrote a service that prints out sys.path into a
logfile. Here is the result:

sys.path=['C:\\Python24\\lib\\site-packages\\win32', 'T:\\Python\\Lib',
'C:\\WINDOWS\\system32\\python24.zip', 'C:\\WINDOWS\\system32',
'C:\\Python24\\DLLs', 'C:\\Python24\\lib',
'C:\\Python24\\lib\\plat-win', 'C:\\Python24\\lib\\lib-tk',
'C:\\Python24\\lib\\site-packages\\win32', 'C:\\Python24',
'C:\\Python24\\lib\\site-packages',
'C:\\Python24\\lib\\site-packages\\PIL',
'C:\\Python24\\lib\\site-packages\\win32\\lib',
'C:\\Python24\\lib\\site-packages\\Pythonwin',
'C:\\Python24\\lib\\site-packages\\wx-2.6-msw-ansi',
'T:\\Python\\Projects\\NamedConnector']

The empty string is not on sys.path. This is very strange, because it is
different when I start the python interactively. The problem was caused
by "C:\WINDOWS\system32", not the empty string. I'm still not sure why
it is included in sys.path, and why '' is not there? I also checked the
Python documentation about sys.path, and read the thread mentioned
before but still sys.path is magical, and magic is not Pythonic. :-)

Anyway, I think I have found the most platform independent solution.
Here it is:
import _socket
import os
import sys
dyndir = os.path.split(_socket.__file__)[0] # This can be "/usr/local/lib/python2.4/lib-dynload" or "C:\Python24\DLLs" or whatever sys.path.append(dyndir)


In most cases, '_socket.pyd' will be the first module that can be
imported, and it will by in the dynaload directory for sure.

I feel this is still unclean code. Do you think that it would be nice to
add new features to the sys module?

sys.dlpath - could be the path to the lib-dynload or DLLs folder
sys.libpath - could be the path to the lib folder

Setting the PYTHONVERBOSE environment variable may assist in showing
where modules are being loaded from.

This cannot be used in conjunction with a windows service, because its
output cannot be seen. :-(
Aug 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alan Toppen | last post by:
I was unable to use the ZipFile class in the zipfile module in Python2.4. I got an error that zlib could not be found. Comparing my Python 2.2...
4
by: Peter | last post by:
Hi, Not sure if this is a proper ng to post this question. Is here anybody who has used zlib? I downloaded 1.2.1 of zlib from...
1
by: Andreas Lobinger | last post by:
Aloha, is a pure _python_ implementation of the zlib available? I have broken zlib streams and need to patch the deocder to get them back. ...
1
by: Dennis Powell | last post by:
Does anyone have a successful implementaion of the zlib.dll in VB. Net they can show me. I'm writting a class encaplsulating zlib functionality and...
2
by: Gregor Mosheh | last post by:
I'm trying to write a Win32 service. The following is straight from Python Programming on Win32 and it doesn't work. Is that book out of date; is...
4
by: shamzz | last post by:
Hi, I've compiled (configure/make/make install) Python 2.4.4 from source on Suse Linux Enterprise Server 9 (x64). I need Python to be compiled...
1
by: mhearne808[insert-at-sign-here]gmail[insert-dot-he | last post by:
I can't seem to get the zlib module to build on an RHEL box. I did the following: 1) Download zlib 1.2.3 2) configure;make;make install 3)...
4
by: MZ | last post by:
Hello! I`ve tried to instal zlib library to use zip functions to pack files into zip archive. I don`t know how I have to configure zlib to...
2
by: rajevar | last post by:
hi, i have seen various post related to this topic but i couldnt resolve my issue yet. Im using python version 2.5 on Linux environment this...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.