繁体   English   中英

使用 Z1D41C853AF58D3A7AE54990CE29417 文件时,如何告诉 python 在哪里可以找到 Windows DLL 文件?

[英]How do I tell python where to find Windows DLL files when using ubuntu (WSL)?

我在ubuntu/WSL shell上运行64-bit WindowsPython version 3.6.9 我的目标是能够使用Thorlabs为一件实验室设备提供的这些.dll files编写我自己的应用程序。 他们的文档听起来很简单(see the [screenshot][1]): just copy over the dll file to your python project folder

但是,当我尝试编写一个简单的测试

from ctypes import *

MC2000BLib = cdll.LoadLibrary("MC2000CommandLibWin32.dll")

我得到的错误是

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    MC2000BLib = cdll.LoadLibrary("MC2000CommandLibWin32.dll")
  File "/usr/lib/python3.6/ctypes/__init__.py", line 426, in LoadLibrary
    return self._dlltype(name)
  File "/usr/lib/python3.6/ctypes/__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: MC2000CommandLibWin32.dll: cannot open shared object file: No such file or directory

到目前为止我已经尝试过:

 - Changed the filename to ```MC2000CommandLibx64.dll``` as they suggested for 64-bit systems but I got the exact same error.
 - Ran an ```os.environ``` output from the python program and saw that ```'LD_LIBRARY_PATH': '/usr/local/lib'``` and I guess ubuntu looks to ```/usr/lib/``` for its .so files.
 - ```export LD_LIBRARY_PATH=C:/Program\ Files\ \(x86\)/Thorlabs/MC2000B/``` and then ```sudo ldconfig```. Same result.

所以问题是我必须将这些dll files放在哪里才能让我的程序识别并使用它们?

他们的文档适用于 Windows,但您使用的是 Linux(在 Windows 内,但这无关紧要),而不是 Windows!

如果在 WSL 中使用 Python,则无法加载 DLL。 WSL 是 Linux - DLL 文件适用于 Windows。

You'll have to use the Windows version of Python instead (which you could still call from WSL if you wanted to, using python.exe instead of python ), or check if there are Linux versions of those library files (typically .so files然后)。

(Also: It won't work here anyway, but in any case the LD_LIBRARY_PATH path format would be wrong too - C:/something is a Windows path (with a forward slash instead of a backslash though), but you are using Linux,所以正确的路径应该是/mnt/c/something ,因为 WSL 将 Windows 的驱动器安装为/mnt/c等)

暂无
暂无

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

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