Importin dll in Python on Linux

安稳与你 提交于 2020-01-05 03:42:26

问题


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")

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

回答1:


er... you can't do that;

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

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.




回答2:


On Linux, we have something called shared object (.so) instead of DLL's.

Long story short: you can't load a Windows DLL on a Linux system. You need to compile a Linux shared library ("edk.so").



来源:https://stackoverflow.com/questions/20762142/importin-dll-in-python-on-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!