如何找到 python 模块包含的 DLL 文件的完整路径?



我正在尝试以编程方式确定特定包的包含/已安装DLL文件的路径。我已经阅读了无数的SO页面,但找不到任何解决方案。也许我错过了什么,这是不可能的?

该软件包是顶点,是通过Cygwin从Windows上的python3绑定的源代码手动安装的。一切正常。

# python3 -c "import os,inspect,capstone; print(os.path.dirname(inspect.getfile(capstone)))"
/usr/lib/python3.6/site-packages/capstone-4.0.0rc1-py3.6.egg/capstone
# python3 -c "import capstone; print(capstone._lib)"
capstone.dll
  1. 上面显示的路径是指向*.egg文件,但该路径实际上并不存在,
    除非您解压缩该文件。
  2. 在 EGG 文件中,位置为./*.egg/capstone/lib/capstone.dll
  3. 但在操作系统中,capstone.dll的真正系统位置在:
    /usr/lib/python3.6/site-packages/capstone/lib

如何在 Python3 中获取真正的路径 (3(?


编辑:

也许这可能有用?但是我想出了这个丑陋的东西,很容易打破,所以希望有一种更python化的方式。

# python3 -c "import capstone; print('DLL path: %s' % capstone._path_list[4] + '/' + capstone.__name__ + '/lib/' + capstone._lib)"
DLL path: /usr/lib/python3.6/site-packages/capstone/lib/capstone.dll

我通过复制"安装">了Capstone

  1. Pythonbindingsdir([GitHub]: capstone-engine/capstone - (master( capstone/bindings/python/capstone( in myCWD

  2. 顶点.dll来自二进制文件.zip文件,位于#1目录中。

在开始准备一个详细(和一般(示例时,我浏览了一下源代码(因为一开始,它没有找到.dll- 因此需要设置${LIBCAPSTONE_PATH}(,并注意到.dll路径存储在capstone._path:)

输出

[cfati@cfati-5510-0:/cygdrive/e/Work/Dev/StackOverflow/q052946558]> ~/sopr.sh
### Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ###
[064bit prompt]> ls
capstone  capstone-4.0-win64.zip  capstone-master.zip
[064bit prompt]> ls capstone
__init__.py   __pycache__  arm_const.py  arm64_const.py  evm.py        m680x.py        m68k.py        mips.py        ppc.py        sparc.py        systemz.py     tms320c64x.py        x86.py        xcore.py
__init__.pyc  arm.py       arm64.py      capstone.dll    evm_const.py  m680x_const.py  m68k_const.py  mips_const.py  ppc_const.py  sparc_const.py  sysz_const.py  tms320c64x_const.py  x86_const.py  xcore_const.py
[064bit prompt]>
[064bit prompt]> python3
Python 3.6.4 (default, Jan  7 2018, 15:53:53)
[GCC 6.4.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import capstone
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/cygdrive/e/Work/Dev/StackOverflow/q052946558/capstone/__init__.py", line 315, in <module>
raise ImportError("ERROR: fail to load the dynamic library.")
ImportError: ERROR: fail to load the dynamic library.
>>>
[064bit prompt]>
[064bit prompt]> LIBCAPSTONE_PATH=$(pwd)/capstone python3
Python 3.6.4 (default, Jan  7 2018, 15:53:53)
[GCC 6.4.0] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import capstone
>>> import os
>>> os.path.join(capstone._path, capstone._lib)
'/cygdrive/e/Work/Dev/StackOverflow/q052946558/capstone/capstone.dll'

最新更新