473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 3401
"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 installation I noticed Python 2.4 was missing a...
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 www.gzip.org/zlib (for windows 98/nt/2000/xp), and used it in my...
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. Wishing a happy day LOBI
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 I keep getting a System.NullReferenceException...
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 there a new way to do services? I searched Google...
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 with Zlib so that I can compile and use Zope. ...
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) Download python 2.5.2 4) configure;make;make install...
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 make it work. I have built up php.ini file and...
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 is the error im getting if i try to import zlib ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.