在 Ubuntu 上的 python 中导入 dll [英] Importing a dll in python on Ubuntu

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

问题描述

我在 Ubuntu 安装的服务器上使用 python 2.6.5.

I am using python 2.6.5 on an Ubuntu intalled server.

我需要为我们的应用程序集成一个 API,在这种情况下,我需要使用 API 提供商提供给我的 DLL.他们关于 api 集成的代码示例是用 Visual Basic 编写的......我在谷歌上搜索并找到了一些使用 ctypes 的示例,我尝试使用 cdllpydll,导致如下错误...

I need to integrate an API for our applicaion, in that case, i needed to use a DLL given to me by the API provider. Their example of code about api integration is written in Visual Basic... I made a search on google and found some examples of using ctypes , and i try using cdll and pydll, which caused the following error...

OSError:/home//some.dll: ELF 头无效

OSError: /home//some.dll: invalid ELF header

一种可能性是使用 IronPython,但我没有太多关于 IronPython 的信息,所以我不确定它是否能完全满足我的需求..

One possibility is using IronPython, but i do not have much information about ironpython so i am not sure if it will handle my needs completely..

是否有任何可用的模块可以让我在 python 上使用该 dll(或者我在现有模块中缺少的任何东西).升级我的python版本很难吗?

Is there any available module that let me use that dll on python (or aynthing that i am missing from the exixting ones). It is hard to upgrade my python version?

推荐答案

DLL 可能是 Windows 生物,但如果 DLL 是纯 .NET"并且不使用特定于 Windows 等的可执行文件,那么它可以经常工作在 Linux 中,通过 Mono.(单声道 ipy.exe).

DLLs may be windows creatures, but if a DLL is 'pure .NET' and doesn't utilize executables specific to windows etc., then it can work often in Linux, through Mono. (mono ipy.exe).

Ironpython 的系统和类似的 Windows 模块被定制为与操作系统无关(在未经测试的程度上).

Ironpython's System and similiar windows modules are customized to be os agnostic (to a untested degree).

我已经在 Ubuntu 中成功运行了 NHibernate、FluentNHibernate、log4net 和其他一些常用的 DLL.

I have successfully run NHibernate, FluentNHibernate, log4net, and a few other commonly used DLLS in Ubuntu.

import clr
import sys
sys.path.append(os.path.abspath('./DLL')) #where your dlls are
clr.AddReference('System')
clr.AddReference('FluentNHibernate')
from FluentNHibernate.Cfg.Db import PostgreSQLConfiguration

关键似乎是以这种方式导入 DLL.如果一个 dll 导入另一个(fluentnhibernate 导入 nhibernate),例如您不需要导入 Nhibernate.

The key seems to be to import DLLs in this fashion. If a dll imports another (fluentnhibernate imports nhibernate), you don't need to import Nhibernate for example.

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆