在Linux上的Python中导入dll

在Linux上的Python中导入dll

本文介绍了在Linux上的Python中导入dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有这段代码可以在Windows上完美运行:

Hello I have this code that runs perfectly on Windows:

    import ctypes
    import sys
    import os
    from ctypes import *
    from numpy import *
    import time
    from ctypes.util import find_library
    libEDK = cdll.LoadLibrary("edk.dll")

我尝试在Ubuntu上运行它,我得到了:

I try running this on Ubuntu and I get this:

Traceback (most recent call last):

 File "/home/nassar/Downloads/python/sds.py", line 9, in <module>
   libEDK = cdll.LoadLibrary("/home/nassar/Desktop/python/edk.dll")
  File "/usr/lib/python2.7/ctypes/__init__.py", line 443, in LoadLibrary
    return self._dlltype(name)
  File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: /home/nassar/Desktop/python/edk.dll: invalid ELF header


推荐答案

er ...您不能这样做;

er... you can't do that;

共享库非常依赖于操作系统,因此为Windows构建的库可能无法在Linux上运行,反之亦然。

Shared libraries are very OS dependent, so a library built for windows cannot possibly work in linux, or visa versa.

除了您可能使用(这是Windows),可能会有些运气可在许多平台上运行的运行时。我肯定在wine中运行Python二进制文件取得了一些成功。

Except that you might get some luck with Wine, which is a Windows runtime which works across many platforms. I have certainly had some success running Python binaries within wine.

这篇关于在Linux上的Python中导入dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 05:53