Installing python with python win32 extensions on

2020-06-18 03:48发布

问题:

I need to keep a large number of Windows XP machines running the same version of python, with an assortment of modules, one of which is python-win32. I thought about installing python on a network drive that is mounted by all the client machines, and just adjust the path on the clients. Python starts up fine from the network, but when importing win32com I get a pop-up error saying:

The procedure entry point ?PyWinObject_AsHANDLE@@YAHPAU_object@@PAPAXH@Z could not be located in the dynamic link library pywintypes24.dll

after dismissing the message dialog I get in the console:

ImportError: DLL load failed: The specified procedure could not be found.

I searched the python directory for the pywintypes24.dll and it is present in "Lib\site-packages\pywin32_system32" .

What am I missing and is there another way in which I can install Python + Python-Win32 + additional module once and have them running on many machines? I don't have access to the Microsoft systems management tools, so I need to be a bit more low-tech than that.

回答1:

On every machine you have to basically run following pywin32_postinstall.py -install once. Assuming your python installation on the network is N:\Python26, run following command on every client:

N:\Python26\python.exe N:\Python26\Scripts\pywin32_postinstall.py -install

Another important thing is Good Luck!. The reason is that you might need to do this as admin. In my case such setup worked for all but one computer. I still did not figure out why.



回答2:

Python (or precisely, the OS) searches the DLLs using os.environ["PATH"] and not by searching sys.path.

So you could start Python using a simple .cmd file instead which adds \server\share\python26 to the path (given the installer (or you) copied the DLLs from \server\share\python26\lib\site-packages\pywin32-system32 to \server\share\python26).

Or, you can add the following code to your scripts before they try to import win32api etc:

    # Add Python installation directory to the path, 
    # because on Windows 7 the pywin32 installer fails to copy
    # the required DLLs to the %WINDIR%\System32 directory and
    # copies them to the Python installation directory instead.
    # Fortunately, in Python it is possible to modify the PATH
    # before loading the DLLs.
    os.environ["PATH"] = sys.prefix + ";" + os.environ.get("PATH")
    import win32gui
    import win32con


回答3:

"""I searched the python directory for the pywintypes24.dll and it is present in "Lib\site-packages\pywin32_system32" """. The existence of the dll is not in question. Is that entry point in that dll?

Have you tried installing exactly the same configuration on a non-network drive?

Have you tried importing other modules in the package?

Have you checked the dlls with the dependency walker or something similar?

Does the "24" in pywintypes24.dll mean Python 2.4? What version of Python are you running?



回答4:

You could use batch files running at boot to

  • Mount the network share (net use \\server\share)
  • Copy the Python and packages installers from the network share to a local folder
  • Check version of the msi installer against the installed version
  • If different, uninstall Python and all version dependent packages
  • Reinstall all packages

This would be pretty much a roll your own central management system for that software.