我正在尝试以编程方式确定特定软件包所包含/已安装DLL文件的路径。我读了无数的SO页,但是找不到任何解决方案。也许我错过了一些东西,这是不可能的吗?
该软件包为capstone,是在Windows上通过 Cygwin 从带有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
*.egg
文件的路径,但是该路径实际上不存在,./*.egg/capstone/lib/capstone.dll
capstone.dll
的实际系统位置在:/usr/lib/python3.6/site-packages/capstone/lib
如何在Python3中获得真实路径(3)?
编辑:
也许this可能有用吗?但是我想出了一个丑陋的东西,它很容易打破,因此希望采用一种更 pythonic 的方式。
# 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
答案 0 :(得分:1)
我通过复制“安装”了顶点:
在开始准备一个详尽(通用)的示例时,我浏览了一下源代码(在开始时,它没有找到 .dll -因此需要设置 $ {LIBCAPSTONE_PATH} ),并注意到 .dll 路径存储在capstone._path
中:)
输出:
[cfati@cfati-5510-0:/cygdrive/e/Work/Dev/StackOverflow/q052946558]> ls capstone capstone-4.0-win64.zip capstone-master.zip [cfati@cfati-5510-0:/cygdrive/e/Work/Dev/StackOverflow/q052946558]> 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 [cfati@cfati-5510-0:/cygdrive/e/Work/Dev/StackOverflow/q052946558]> [cfati@cfati-5510-0:/cygdrive/e/Work/Dev/StackOverflow/q052946558]> 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. >>> [cfati@cfati-5510-0:/cygdrive/e/Work/Dev/StackOverflow/q052946558]> [cfati@cfati-5510-0:/cygdrive/e/Work/Dev/StackOverflow/q052946558]> 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'