How to call Wine dll from python on Linux?
Doesn't Wine provide *.so
versions of the dlls? I seem to have /usr/lib32/wine/advapi32.dll.so
, for example.
If you're on a 64-bit machine, keep in mind that you'll need a 32-bit version of Python to load 32-bit libraries.
Importin dll in Python on Linux
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.
Importing a dll in python on Ubuntu
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's System and similiar windows modules are customized to be os agnostic (to a untested degree).
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
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.
Can I wrap windows dll to use it in Python under Linux?
Disclaimer: Depending on the context, the following is certainly NOT the best approach. It is just ONE possible approach that kind of fits the description.
I wrote a small Python module for calling into Windows DLLs from Python on Linux. It is based on IPC between a regular Linux/Unix Python process and a Wine-based Python process. Because I have needed it in too many different use-cases / scenarios myself, I designed it as a "generic" ctypes
module drop-in replacement, which does most of the required plumbing automatically in the background.
Example: Assume you're in Python on Linux, you have Wine installed, and you want to call into msvcrt.dll
(the Microsoft C runtime library). You can do the following:
from zugbruecke import ctypes
dll_pow = ctypes.cdll.msvcrt.pow
dll_pow.argtypes = (ctypes.c_double, ctypes.c_double)
dll_pow.restype = ctypes.c_double
print('You should expect "1024.0" to show up here: "%.1f".' % dll_pow(2.0, 10.0))
Source code (LGPL), PyPI package & documentation.
It's still a bit rough around the edges (i.e. alpha and insecure), but it does handle most types of parameters (including pointers).
I'd be really interested to see how it behaves and performs when used with a hardware driver. Feedback is highly welcomed!
Related Topics
Get File Creation Time with Python on Linux
Cannot Get Environment Variables in Django Settings File
Opening a Python Thread in a New Console Window
Creating Pyqt5 Buttons in a Loop: All Buttons Trigger the Same Callback
Why Is Signal.Sigalrm Not Working in Python on Windows
/Usr/Bin/Ld: Cannot Find -Lpython2.7
Anaconda: Disable Prompt Change
How to Create a User in Linux Using Python
Multiple Instances of Python Running Simultaneously Limited to 35
What Is the Easiest Way to Detect Key Presses in Python 3 on a Linux MAChine
Better Way to Script Usb Device Mount in Linux
Linux/Python: Encoding a Unicode String for Print
Python: Interplay Between Lib/Site-Packages/Site.Py and Lib/Site.Py
Linux:Python:Clear Input Buffer Before Raw_Input()
Python: Complexity of Os.Path.Exists with a Ext4 Filesystem