简体   繁体   English

python27.dll的位置来自python本身

[英]location of python27.dll from python itself

Is there a way to get the path of python27.dll from the python interpreter itself in windows. 有没有办法从Windows中的python解释器本身获取python27.dll的路径。

I am looking for something like sys.executable that can get me the path to python27.dll ( just the directory ould do as well) 我正在寻找像sys.executable这样的东西可以让我获得python27.dll的路径(只是目录也应该这样做)

You can use pywin32 to get a list of DLLs used by the python executable, then search those for python27.dll: 您可以使用pywin32获取python可执行文件使用的DLL列表,然后搜索python27.dll:

import win32process

for process in win32process.EnumProcessModules(-1):
  name = win32process.GetModuleFileNameEx(-1, process)
  if "python27.dll" in name:
    print name

In the above example, -1 is the pseudo-process handle for the current process. 在上面的示例中,-1是当前进程的伪进程句柄。 You can also get the handle via: 您还可以通过以下方式获取句柄:

curHandle = win32process.GetCurrentProcess()

pywin32 is available for download here: pywin32可在此下载:

http://sourceforge.net/projects/pywin32/files/pywin32/Build%20219/ http://sourceforge.net/projects/pywin32/files/pywin32/Build%20219/

If you assume that, python27.dll get installed at system path, you can extract the absolute path by this way: 如果你认为python27.dll安装在系统路径上,你可以通过这种方式提取绝对路径:

import subprocess
print subprocess.check_call("where python27.dll")

output: 输出:

C:\Windows\System32\python27.dll
0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM