473,721 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\Proj ects\NamedConne ctor\Service.py ", line 17, in ?
from Processor import *
File "c:\Python\Proj ects\NamedConne ctor\Processor. py", line 35, in ?
from mess import MessageSocket
File "T:\Python\Lib\ mess\MessageSoc ket.py", line 31, in ?
import zlib
exceptions.Imp ortError: dynamic module does not define init function
(initzlib)
-------------


Aug 15 '05 #1
6 3426
"Laszlo Zsolt Nagy" <ga*****@geoche msource.com> schrieb im Newsbeitrag
news:ma******** *************** *************** *@python.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\Proj ects\NamedConne ctor\Service.py ", line 17, in ?
| > from Processor import *
| > File "c:\Python\Proj ects\NamedConne ctor\Processor. py", line 35, in ?
| > from mess import MessageSocket
| > File "T:\Python\Lib\ mess\MessageSoc ket.py", line 31, in ?
| > import zlib
| >exceptions.Imp ortError: 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*****@geoche msource.com> schrieb im Newsbeitrag
news:ma******* *************** *************** **@python.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\Proj ects\NamedConne ctor\Service.py ", line 17, in ?
| > from Processor import *
| > File "c:\Python\Proj ects\NamedConne ctor\Processor. py", line 35, in ?
| > from mess import MessageSocket
| > File "T:\Python\Lib\ mess\MessageSoc ket.py", line 31, in ?
| > import zlib
| >exceptions.Imp ortError: 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\produ ct\10.1.0\db_1\ bin;c:\oracle\p roduct\10.1.0\d b_1\jre\1.4.2\b in\client;c:\or acle\product\10 .1.0\db_1\jre\1 .4.2\bin;%Syste mRoot%\system32 ;%SystemRoot%;% SystemRoot%\Sys tem32\Wbem;C:\P rogram
Files\Common Files\GTK\2.0\b in

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*****@geoche msource.com> schrieb im Newsbeitrag
news:ma******** *************** *************** *@python.org...
| vincent wehren wrote:
|
| >"Laszlo Zsolt Nagy" <ga*****@geoche msource.com> schrieb im Newsbeitrag
| >news:ma******* *************** *************** **@python.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\Proj ects\NamedConne ctor\Service.py ", line 17, in ?
| >| > from Processor import *
| >| > File "c:\Python\Proj ects\NamedConne ctor\Processor. py", line 35, in ?
| >| > from mess import MessageSocket
| >| > File "T:\Python\Lib\ mess\MessageSoc ket.py", line 31, in ?
| >| > import zlib
| >| >exceptions.Imp ortError: 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\produ ct\10.1.0\db_1\ bin;c:\oracle\p roduct\10.1.0\d b_1\jre\1.4.2\b in\client;c:\or acle\product\10 .1.0\db_1\jre\1 .4.2\bin;%Syste mRoot%\system32 ;%SystemRoot%;% SystemRoot%\Sys tem32\Wbem;C:\P rogram
| Files\Common Files\GTK\2.0\b in
|
| 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 \site-packages\win32; c:\oracle\produ ct\10.1.0\db_1\ bin;c:\oracle\p roduct\10.1.0\d b_1\jre\1.4.2\b in\client;c:\or acle\product\10 .1.0\db_1\jre\1 .4.2\bin;%Syste mRoot%\system32 ;%SystemRoot%;% SystemRoot%\Sys tem32\Wbem;C:\P rogram
| Files\Common Files\GTK\2.0\b in
|
| 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:\Python2 4\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\Proj ects\NamedConne ctor>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 win32serviceuti l, 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\produ ct\10.1.0\db_1\ bin;c:\oracle\p roduct\10.1.0\d b_1\jre\1.4.2\b in\client;c:\or acle\product\10 .1.0\db_1\jre\1 .4.2\bin;%Syste mRoot%\system32 ;%SystemRoot%;% SystemRoot%\Sys tem32\Wbem;C:\P rogram

| Files\Common Files\GTK\2.0\b in
|
| 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:\Python2 4\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\Proj ects\NamedConne ctor>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 win32serviceuti l, 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%\system 32 (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%\syste m32 (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\\Li b',
'C:\\WINDOWS\\s ystem32\\python 24.zip', 'C:\\WINDOWS\\s ystem32',
'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\\Pytho nwin',
'C:\\Python24\\ lib\\site-packages\\wx-2.6-msw-ansi',
'T:\\Python\\Pr ojects\\NamedCo nnector']

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\sys tem32", 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\DL Ls" 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
3750
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 certain file: /usr/lib/python2.2/lib-dynload/zlibmodule.so. Unable to find a more elegant solution, I copied the file from my Python 2.2 directory into my Python 2.4 directory. When running my Python script it gives a warning: ...
4
1867
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 program to zip/unzip files. When I use the zipper class in zlib to zip a folder, I got a zip file with the SAME SIZE of zip file created (on the same folder) with the 'ZipTest' program downloaded from the site. But the problem is that the zip file...
1
1613
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
7939
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 (Object reference not set to an instance of an object) when I try to call the dll's compress function. The function in the dll is declared as such: int compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen) I've...
2
5553
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 for hours trying to find any other method, and have been beating on this one for 5 more hours. The present error is: C:\Tester>python tester.py debug Debugging service Tester - press Ctrl+C to stop. Error 0xC0000004 - Python could not import...
4
7436
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. After installing Python, zlib doesn't seem to have been compiled with it, I've checked the /usr/local/lib/python2.4/lib-dynload/ folder and
1
4419
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 5) >>import zlib ="ImportError: No module named zlib" In the make install step for python, I notice there are the following
4
2929
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 I`ve put such line --with-zlib=/home/domena_nazwa/domains/test.com/public_html/gallery/lib/zziplib.lib
2
10350
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 # python -c 'import zlib' Traceback (most recent call last): File "<string>", line 1, in <module>
0
8840
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9367
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9064
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8007
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4484
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4753
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3189
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.