windows 在网络驱动器上安装带有 python win32 扩展的 python

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2319495/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:00:44  来源:igfitidea点击:

Installing python with python win32 extensions on a network drive

pythonwindowsnetworkingshare

提问by florin

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:

我需要保留大量运行相同版本 python 的 Windows XP 机器,以及各种模块,其中之一是 python-win32。我想过在所有客户端机器都挂载的网络驱动器上安装python,只需调整客户端上的路径即可。Python 从网络启动良好,但在导入 win32com 时,我收到一个弹出错误消息:

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

过程入口点 ?PyWinObject_AsHANDLE@@YAHPAU_object@@PAPAXH@Z 无法在动态链接库 pywintypes24.dll 中定位

after dismissing the message dialog I get in the console:

关闭消息对话框后,我进入控制台:

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

导入错误:DLL 加载失败:找不到指定的过程。

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

我在 python 目录中搜索了 pywintypes24.dll,它存在于 "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.

我错过了什么,还有另一种方法可以安装 Python + Python-Win32 + 附加模块一次并让它们在多台机器上运行吗?我无法访问 Microsoft 系统管理工具,因此我需要比这低一点。

回答by van

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

在每台机器上,您基本上都必须运行pywin32_postinstall.py -install一次。假设您在网络上的 python 安装是N:\Python26,请在每个客户端上运行以下命令:

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.

另一个重要的事情是Good Luck!。原因是您可能需要将其作为admin. 就我而言,这种设置适用于除一台计算机之外的所有计算机。我还是不明白为什么。

回答by Henning

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

Python(或者准确地说,操作系统)使用 os.environ["PATH"] 而不是通过搜索 sys.path 来搜索 DLL。

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).

因此,您可以使用简单的 .cmd 文件启动 Python,该文件将 \server\share\python26 添加到路径中(假设安装程序(或您)从 \server\share\python26\lib\site-packages\pywin32- system32 到 \server\share\python26)。

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

或者,您可以在脚本尝试导入 win32api 等之前将以下代码添加到脚本中:

    # 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

回答by John Machin

"""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?

"""我在 python 目录中搜索了 pywintypes24.dll,它存在于 "Lib\site-packages\pywin32_system32" """ 中。dll的存在是没有问题的。那个入口点在那个 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?

您是否使用依赖项walker或类似的东西检查过dll?

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

pywintypes24.dll 中的“24”是否表示 Python 2.4?你在运行什么版本的 Python?

回答by Esteban Küber

You could use batch files running at bootto

您可以使用在启动时运行的批处理文件

  • 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
  • 挂载网络共享 ( net use \\server\share)
  • 将 Python 和包安装程序从网络共享复制到本地文件夹
  • 根据已安装的版本检查 msi 安装程序的版本
  • 如果不同,卸载 Python 和所有版本相关的包
  • 重新安装所有软件包

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

这几乎是您自己的该软件的中央管理系统。