Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pushing Python to Windows workstations

12 views
Skip to first unread message

C42

unread,
May 5, 2003, 10:57:29 AM5/5/03
to
I need to install Python and win32all to all of the PCs on my
Windows domain (100+). I have domain admin rights and would like to push
Python/win32all to the workstations automatically.

Does anyone have a list of what the Python installer does, so I can
perform the same procedure remotely? Or, is there an easier way to do this?

Lexy Zhitenev

unread,
May 5, 2003, 11:12:49 AM5/5/03
to

"C42" <nos...@nospam.net> wrote in message:
news:tZuta.248$413.1...@newshog.newsread.com...

You can use ActiveState ActivePython, which includes win32all package and is
distributed in a MSI package. You can install Python via Group Policy
snap-in of MMC.

Regards, Lexy.


Gerhard Häring

unread,
May 5, 2003, 11:05:05 AM5/5/03
to

They should have a /Q or /S option for silent installation.

You could probably use a domain logon script to silently install Python
on all workstations.

-- Gerhard

Peter Hansen

unread,
May 5, 2003, 12:51:18 PM5/5/03
to

Can you consider not installing it on all machines, but running from a
network install?

We don't have 100 machines here... only about 55 at the moment, but they
all have access to a nice central install complete with win32all. Works
nicely, no worries about maintaining 55 machines...

-Peter

C42

unread,
May 5, 2003, 1:45:56 PM5/5/03
to
Can you tell me more about how you accomplished this? I have often
wondered if there was a way to have Python run from a network share.

Thanks!

Peter Hansen

unread,
May 5, 2003, 2:31:52 PM5/5/03
to
C42 wrote:
> Peter Hansen wrote:
> > C42 wrote:
> >>I need to install Python and win32all to all of the PCs on my
> >>Windows domain (100+).
> >
> > Can you consider not installing it on all machines, but running from a
> > network install?
>
> Can you tell me more about how you accomplished this? I have often
> wondered if there was a way to have Python run from a network share.

Well, first step is to install everything you need to a single machine,
in the usual way. That's necessary even for extension modules because
many installers *insist* on installing only into Python installations
that are listed in the registry. Kind of a shame, since it would probably
be pretty easy to let a user enter a path to override, but for pretty
much everything is anal about this in the same way so it's just a fact of life.

After everything is installed, and tested :-), just do an XCOPY from
the c:\python22 (or whatever) folder to the network drive. We have our
stuff under i:\sw\a\python for example...

Next step (in our case, probably not necessary in general) is to have a
single network folder where various batch files run: i:\sw\utils in our
case. Here we have a "python.bat" file which does two things only:

@echo off
set pythonhome=i:\sw\a\python
%pythonhome%\python %1 %2 %3 %4 %5 %6 %7 %8 %9

Yes, DOS batch files are ugly as sin, but it works adequately so long
as you don't have a zillion(*) command line options. (* where zillion
is defined as "greater than nine...)

Now that handles the basic Python stuff. Next step is win32all. It
might look like everything is working fine at this point, but you may
be running on a machine where some DLL files were copied into the
c:\windows folder. If those are not present, not everything will work
as well.

Our solution was to use a sitecustomize.py file to ensure that pythoncom.dll
and pywintypes.dll are always imported at startup, and with a bit of code
that ensures they are found by loading them with imp.load_module() using
sys.exec_prefix as the path.

I don't entirely recall sure why this latter step is necessary, but I think
it was because some of the win32all stuff (like win32com) finding its own
location by looking at the path from which pythoncom and/or pywintypes were
loaded. If they are loaded from some other location, win32com can't find
itself and barfs.

I can post the current script for doing this magic if someone is interested.
(Please be prepared to test once I post though... I'd hate to have this
cruft stuck in the archives without it having been put through the ringer
by someone outside of my group. What works for us might be a disaster for
someone else, a year down the road.)

-Peter

C42

unread,
May 5, 2003, 2:49:11 PM5/5/03
to
I found the following info.

Running Python From a Shared Network Installation (NT)
http://starship.python.net/crew/jjkunce/netinstall/

Peter Hansen

unread,
May 5, 2003, 4:32:48 PM5/5/03
to C42
C42 wrote:
>
> I found the following info.
>
> Running Python From a Shared Network Installation (NT)
> http://starship.python.net/crew/jjkunce/netinstall/

That technique still requires copying files directly to each individual
machine.

Which is fine.

If you like that kind of thing.

-Peter

C42

unread,
May 5, 2003, 4:51:19 PM5/5/03
to
If you wouldn't mind posting the script that would be great. I've been
trying to get this to work all afternoon and so far haven't had much luck.

Peter Hansen

unread,
May 5, 2003, 6:45:57 PM5/5/03
to
C42 wrote:
>
> If you wouldn't mind posting the script that would be great. I've been
> trying to get this to work all afternoon and so far haven't had much luck.

Okay, here goes. For simplicity, I assume you have the following files in a
directory that is in sys.path. You can use PYTHONPATH, or .pth files as noted
in site.py or some other approach. The files are:

sitecustomize.py (loads automatically from site.py)
pythoncom.py (loaded if you import pythoncom)
pywintypes.py (loaded if you import pywintypes)
dll_import.py (utility routines used by above two)


sitecustomize.py contains:
-------------------------
# site customization file for network installation of Python,
# to workaround problem loading win32api before either
# of these is loaded.

import pythoncom
import pywintypes
-------------------------


pythoncom.py contains:
-------------------------
# fake some stuff out so anyone can import pythoncom from a network install

import dll_import
dll_import.dll_import('pythoncom')
-------------------------


pywintypes.py contains:
-------------------------
# fake some stuff out so anyone can import pywintypes from a network install

import dll_import
dll_import.dll_import('pywintypes')
-------------------------


dll_import.py contains:
-------------------------
# fake some stuff out so importing win32 works with a network install

import imp, sys, os

# patch pre-2.2 Pythons
if not hasattr(sys, '_getframe'):
def _getframe():
try:
1/0
except:
f = sys.exc_info()[2].tb_frame.f_back
return f

sys._getframe = _getframe


def dll_import(modulename):
# find my caller
f = sys._getframe().f_back

# build name of DLL with version number
ver = '%1d%1d' % sys.version_info[:2]
filename = modulename + ver + '.dll'
dllpath = os.path.join(sys.exec_prefix, filename)

# Python can load the module
mod = imp.load_module(modulename, None, dllpath, ('.dll', 'rb',
imp.C_EXTENSION))

# inject it into the global module list.
sys.modules[modulename] = mod

# And finally inject it into the globals() of my caller
f.f_globals[modulename] = mod
-------------------------


Let me know if that (a) works, (b) is clear enough to use as-is. If
not the former, I'll try to help troubleshoot. If not the latter,
I *might* be able to help explain, but as I said this was developed
by trial-and-error. Perhaps Mark Hudson or someone else can explain
why this appears to be necessary.

-Peter

C42

unread,
May 6, 2003, 4:55:46 PM5/6/03
to
I created the following code to add the path statements I need. When I
placed this before "import win32net", it worked just fine.


import sys

my_path = 'I:\\Python\\lib\\site-packages\\win32'
sys.path.append(my_path)
my_path = 'I:\\Python\\lib\\site-packages\\win32\\lib'
sys.path.append(my_path)
my_path = 'I:\\Python\\lib\\site-packages'
sys.path.append(my_path)

>> Per your instructions, I copied my installation of python (2.2)
>> including win32all to the network share and then created the python
>> files you mentioned and placed them in I:\Python\Lib.
>>
>> I then created the python.bat file and tried it out. It ran my one line
>> "Hello World" script with no problem. However, when I try to run my
>> program which contain references to win32net and win32api, it stops and
>> says "ImportError: No module named win32net".


That happens here as well, and I recall someone noting that win32net
does NOT work under Windows 98 (which is what we're running). Lacking
an available WinNT/XP machine for testing that theory, I can't confirm.
Google probably would find a reference if I'm right.

Correction... the error I get is:

Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: DLL load failed: A device attached to the system is not
functioning

With pythoncom, pywintypes, win32api, win32gui, win32com, ... all work
just fine. Only win32net produces that error for me.

Putting a "import sys; print sys.path" just before the import that fails
and verifying that it contains the win32 folder under your Python
installation
would be a good idea.

-Peter


Peter Hansen

unread,
May 6, 2003, 6:34:17 PM5/6/03
to
C42 wrote:
>
> I created the following code to add the path statements I need. When I
> placed this before "import win32net", it worked just fine.
>
> import sys
>
> my_path = 'I:\\Python\\lib\\site-packages\\win32'
> sys.path.append(my_path)
> my_path = 'I:\\Python\\lib\\site-packages\\win32\\lib'
> sys.path.append(my_path)
> my_path = 'I:\\Python\\lib\\site-packages'
> sys.path.append(my_path)

Interesting... are you sure all three are required?

Is this i:\python\lib\site-packages folder the standard site-packages,
or a look-alike you created elsewhere (i.e. not under the folder where
python.exe resides)?

Are you running Win98? If so, I'll see whether I can get my win32net
to load as well with something similar, or cleaner. You certainly don't
want to go doing that wherever you need it... try using a .pth file
instead, though note that sys.path should already include the site-packages
folder if things are set up correctly. Do you have PYTHONHOME set
properly to point to i:\python ?

-Peter

0 new messages