Python ctypes.cdll.LoadLibrary() Examples
The following are 30
code examples of ctypes.cdll.LoadLibrary().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ctypes.cdll
, or try the search function
.
Example #1
Source File: __init__.py From SwiftKitten with MIT License | 7 votes |
def find_yajl_ctypes(required): ''' Finds and loads yajl shared object of the required major version (1, 2, ...) using ctypes. ''' # Importing ``ctypes`` should be in scope of this function to prevent failure # of `backends`` package load in a runtime where ``ctypes`` is not available. # Example of such environment is Google App Engine (GAE). from ctypes import util, cdll so_name = util.find_library('yajl') if so_name is None: raise YAJLImportError('YAJL shared object not found.') yajl = cdll.LoadLibrary(so_name) require_version(yajl.yajl_version(), required) return yajl
Example #2
Source File: shared_lib.py From AVSR-Deep-Speech with GNU General Public License v2.0 | 6 votes |
def check_so(soname): """ Verify that we do have the 'soname' lib present in the system, and that it can be loaded. """ if len(get_available_gpus()) == 0: return None # Try to force load lib, this would fail if the lib is not there :) try: lib = cdll.LoadLibrary(soname) print("INFO: Found so as", lib) assert lib.__class__.__name__ == 'CDLL' assert lib._name == soname return True except OSError as ex: print("WARNING:", ex) return False
Example #3
Source File: action_playsound.py From dragonfly with GNU Lesser General Public License v3.0 | 6 votes |
def _get_pa_instance(): # Suppress initial ALSA messages if using ALSA. # Got this from: https://stackoverflow.com/a/17673011/12157649 try: asound = cdll.LoadLibrary('libasound.so') c_error_handler = ERROR_HANDLER_FUNC( lambda filename, line, function, err, fmt: None ) asound.snd_lib_error_set_handler(c_error_handler) except: # We'll most likely get here if the Port Audio host API isn't ALSA. asound = None # Create the pa instance. pa = pyaudio.PyAudio() # If necessary, restore the original error handler. if asound: asound.snd_lib_error_set_handler(None) return pa
Example #4
Source File: rishpilo.py From python-ilorest-library-old with Apache License 2.0 | 6 votes |
def __init__(self): if os.name == 'nt': fhandle = c_void_p() try: self.dll = cdll.LoadLibrary("ilorest_chif.dll") except: self.dll = cdll.LoadLibrary("hprest_chif.dll") self.dll.ChifInitialize(None) self.dll.ChifCreate.argtypes = [c_void_p] self.dll.ChifCreate.restype = c_uint32 try: status = self.dll.ChifCreate(byref(fhandle)) if status != BlobReturnCodes.SUCCESS: raise HpIloInitialError("Error %s occurred while trying " \ "to open a channel to iLO" % status) self.fhandle = fhandle self.dll.ChifSetRecvTimeout(self.fhandle, 30000) except Exception, excp: self.unload() raise excp
Example #5
Source File: utils.py From Retropie-CRT-Edition with GNU General Public License v3.0 | 6 votes |
def set_procname(p_sProcName): from ctypes import cdll, byref, create_string_buffer libc = cdll.LoadLibrary('libc.so.6') #Loading a 3rd party library C buff = create_string_buffer(len(p_sProcName)+1) #Note: One larger than the name (man prctl says that) buff.value = p_sProcName #Null terminated string as it should be libc.prctl(15, byref(buff), 0, 0, 0) #Refer to "#define" of "/usr/include/linux/prctl.h" for the misterious value 16 & arg[3..5] are zero as the man page says.
Example #6
Source File: ctypes_errno.py From darkc0de-old-stuff with GNU General Public License v3.0 | 6 votes |
def _errno_location(): """ Try to get errno integer from libc using __errno_location_sym function. This function is specific to OS with "libc.so.6" and may fails for thread-safe libc. """ from ctypes import cdll try: libc = cdll.LoadLibrary("libc.so.6") except OSError: # Unable to open libc dynamic library return None try: __errno_location = libc.__errno_location_sym except AttributeError: # libc doesn't have __errno_location return None __errno_location.restype = POINTER(c_int) return __errno_location()[0]
Example #7
Source File: halide.py From ProxImaL with MIT License | 6 votes |
def run(self, *args): """ Execute Halide code that was compiled before. """ # Output names that our halide compilation produces function_name, function_name_c, output_lib = output_names( self.func, self.generator_source, self.builddir) # Run args_ctype = convert_to_ctypes(args, function_name_c) # Directly load the lib launch = cdll.LoadLibrary(output_lib) # Call error = getattr(launch, function_name_c)(*args_ctype) if error != 0: print('Halide call to {0} returned {1}'.format(function_name_c, error), file=sys.stderr) exit()
Example #8
Source File: library.py From picosdk-python-wrappers with ISC License | 6 votes |
def _load(self): library_path = find_library(self.name) if library_path is None: env_var_name = "PATH" if sys.platform == 'win32' else "LD_LIBRARY_PATH" raise CannotFindPicoSDKError("PicoSDK (%s) not found, check %s" % (self.name, env_var_name)) try: if sys.platform == 'win32': from ctypes import WinDLL result = WinDLL(library_path) else: from ctypes import cdll result = cdll.LoadLibrary(library_path) except OSError as e: raise CannotOpenPicoSDKError("PicoSDK (%s) not compatible (check 32 vs 64-bit): %s" % (self.name, e)) return result
Example #9
Source File: similarity.py From MARA_Framework with GNU Lesser General Public License v3.0 | 6 votes |
def __init__(self, path="./libsimilarity/libsimilarity.so"): super(SIMILARITYNative, self).__init__(True) self._u = cdll.LoadLibrary( path ) self._u.compress.restype = c_uint self._u.ncd.restype = c_int self._u.ncs.restype = c_int self._u.cmid.restype = c_int self._u.entropy.restype = c_double self._u.levenshtein.restype = c_uint self._u.kolmogorov.restype = c_uint self._u.bennett.restype = c_double self._u.RDTSC.restype = c_double self.__libsim_t = LIBSIMILARITY_T() self.set_compress_type( ZLIB_COMPRESS )
Example #10
Source File: cgroups.py From benchexec with Apache License 2.0 | 6 votes |
def _register_process_with_cgrulesengd(pid): """Tell cgrulesengd daemon to not move the given process into other cgroups, if libcgroup is available. """ # Logging/printing from inside preexec_fn would end up in the output file, # not in the correct logger, thus it is disabled here. from ctypes import cdll try: libcgroup = cdll.LoadLibrary("libcgroup.so.1") failure = libcgroup.cgroup_init() if failure: pass else: CGROUP_DAEMON_UNCHANGE_CHILDREN = 0x1 failure = libcgroup.cgroup_register_unchanged_process( pid, CGROUP_DAEMON_UNCHANGE_CHILDREN ) if failure: pass # print('Could not register process to cgrulesndg, error {}. ' # 'Probably the daemon will mess up our cgroups.'.format(success)) except OSError: pass
Example #11
Source File: util.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test(): from ctypes import cdll if os.name == "nt": print(cdll.msvcrt) print(cdll.load("msvcrt")) print(find_library("msvcrt")) if os.name == "posix": # find and load_version print(find_library("m")) print(find_library("c")) print(find_library("bz2")) # getattr ## print cdll.m ## print cdll.bz2 # load if sys.platform == "darwin": print(cdll.LoadLibrary("libm.dylib")) print(cdll.LoadLibrary("libcrypto.dylib")) print(cdll.LoadLibrary("libSystem.dylib")) print(cdll.LoadLibrary("System.framework/System")) else: print(cdll.LoadLibrary("libm.so")) print(cdll.LoadLibrary("libcrypt.so")) print(find_library("crypt"))
Example #12
Source File: util.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
def test(): from ctypes import cdll if os.name == "nt": print cdll.msvcrt print cdll.load("msvcrt") print find_library("msvcrt") if os.name == "posix": # find and load_version print find_library("m") print find_library("c") print find_library("bz2") # getattr ## print cdll.m ## print cdll.bz2 # load if sys.platform == "darwin": print cdll.LoadLibrary("libm.dylib") print cdll.LoadLibrary("libcrypto.dylib") print cdll.LoadLibrary("libSystem.dylib") print cdll.LoadLibrary("System.framework/System") else: print cdll.LoadLibrary("libm.so") print cdll.LoadLibrary("libcrypt.so") print find_library("crypt")
Example #13
Source File: v3d.py From py-videocore with MIT License | 5 votes |
def __init__(self, driver, library_path = '/opt/vc/lib'): self.lib = cdll.LoadLibrary('{}/libbcm_host.so'.format(library_path)) self.peri = None
Example #14
Source File: util.py From odoo13-x64 with GNU General Public License v3.0 | 5 votes |
def test(): from ctypes import cdll if os.name == "nt": print(cdll.msvcrt) print(cdll.load("msvcrt")) print(find_library("msvcrt")) if os.name == "posix": # find and load_version print(find_library("m")) print(find_library("c")) print(find_library("bz2")) # load if sys.platform == "darwin": print(cdll.LoadLibrary("libm.dylib")) print(cdll.LoadLibrary("libcrypto.dylib")) print(cdll.LoadLibrary("libSystem.dylib")) print(cdll.LoadLibrary("System.framework/System")) # issue-26439 - fix broken test call for AIX elif sys.platform.startswith("aix"): from ctypes import CDLL if sys.maxsize < 2**32: print(f"Using CDLL(name, os.RTLD_MEMBER): {CDLL('libc.a(shr.o)', os.RTLD_MEMBER)}") print(f"Using cdll.LoadLibrary(): {cdll.LoadLibrary('libc.a(shr.o)')}") # librpm.so is only available as 32-bit shared library print(find_library("rpm")) print(cdll.LoadLibrary("librpm.so")) else: print(f"Using CDLL(name, os.RTLD_MEMBER): {CDLL('libc.a(shr_64.o)', os.RTLD_MEMBER)}") print(f"Using cdll.LoadLibrary(): {cdll.LoadLibrary('libc.a(shr_64.o)')}") print(f"crypt\t:: {find_library('crypt')}") print(f"crypt\t:: {cdll.LoadLibrary(find_library('crypt'))}") print(f"crypto\t:: {find_library('crypto')}") print(f"crypto\t:: {cdll.LoadLibrary(find_library('crypto'))}") else: print(cdll.LoadLibrary("libm.so")) print(cdll.LoadLibrary("libcrypt.so")) print(find_library("crypt"))
Example #15
Source File: zbar_library.py From pyzbar with MIT License | 5 votes |
def load(): """Loads the libzar shared library and its dependencies. """ if 'Windows' == platform.system(): # Possible scenarios here # 1. Run from source, DLLs are in pyzbar directory # cdll.LoadLibrary() imports DLLs in repo root directory # 2. Wheel install into CPython installation # cdll.LoadLibrary() imports DLLs in package directory # 3. Wheel install into virtualenv # cdll.LoadLibrary() imports DLLs in package directory # 4. Frozen # cdll.LoadLibrary() imports DLLs alongside executable fname, dependencies = _windows_fnames() def load_objects(directory): # Load dependencies before loading libzbar dll deps = [ cdll.LoadLibrary(str(directory.joinpath(dep))) for dep in dependencies ] libzbar = cdll.LoadLibrary(str(directory.joinpath(fname))) return deps, libzbar try: dependencies, libzbar = load_objects(Path('')) except OSError: dependencies, libzbar = load_objects(Path(__file__).parent) else: # Assume a shared library on the path path = find_library('zbar') if not path: raise ImportError('Unable to find zbar shared library') libzbar = cdll.LoadLibrary(path) dependencies = [] return libzbar, dependencies
Example #16
Source File: dmtx_library.py From pylibdmtx with MIT License | 5 votes |
def load(): """Loads the libdmtx shared library. """ if 'Windows' == platform.system(): # Possible scenarios here # 1. Run from source, DLLs are in pylibdmtx directory # cdll.LoadLibrary() imports DLLs in repo root directory # 2. Wheel install into CPython installation # cdll.LoadLibrary() imports DLLs in package directory # 3. Wheel install into virtualenv # cdll.LoadLibrary() imports DLLs in package directory # 4. Frozen # cdll.LoadLibrary() imports DLLs alongside executable fname = _windows_fname() try: libdmtx = cdll.LoadLibrary(fname) except OSError: libdmtx = cdll.LoadLibrary( str(Path(__file__).parent.joinpath(fname)) ) else: # Assume a shared library on the path path = find_library('dmtx') if not path: raise ImportError('Unable to find dmtx shared library') libdmtx = cdll.LoadLibrary(path) return libdmtx
Example #17
Source File: SoExtention.py From THULAC-Python with MIT License | 5 votes |
def __init__(self, model_path, user_dict_path, t2s, just_seg, pre_alloc_size=1024*1024*16): root = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) #设置so文件的位置 self._lib = cdll.LoadLibrary(root+'/libthulac.so') #读取so文件 self._lib.init(c_char_p(fixCCP(model_path)), c_char_p(fixCCP(user_dict_path)), int(pre_alloc_size), int(t2s), int(just_seg)) #调用接口进行初始化
Example #18
Source File: mceq_config.py From MCEq with BSD 3-Clause "New" or "Revised" License | 5 votes |
def set_mkl_threads(nthreads): global mkl_threads, mkl from ctypes import cdll, c_int, byref mkl = cdll.LoadLibrary(mkl_path) # Set number of threads mkl_threads = nthreads mkl.mkl_set_num_threads(byref(c_int(nthreads))) if debug_level >= 5: print('MKL threads limited to {0}'.format(nthreads))
Example #19
Source File: util.py From filmkodi with Apache License 2.0 | 5 votes |
def test(): from ctypes import cdll if os.name == "nt": sys.stdout.write('%s\n' % (cdll.msvcrt,)) sys.stdout.write('%s\n' % (cdll.load("msvcrt"),)) sys.stdout.write('%s\n' % (find_library("msvcrt"),)) if os.name == "posix": # find and load_version sys.stdout.write('%s\n' % (find_library("m"),)) sys.stdout.write('%s\n' % (find_library("c"),)) sys.stdout.write('%s\n' % (find_library("bz2"),)) # getattr ## print_ cdll.m ## print_ cdll.bz2 # load if sys.platform == "darwin": sys.stdout.write('%s\n' % (cdll.LoadLibrary("libm.dylib"),)) sys.stdout.write('%s\n' % (cdll.LoadLibrary("libcrypto.dylib"),)) sys.stdout.write('%s\n' % (cdll.LoadLibrary("libSystem.dylib"),)) sys.stdout.write('%s\n' % (cdll.LoadLibrary("System.framework/System"),)) else: sys.stdout.write('%s\n' % (cdll.LoadLibrary("libm.so"),)) sys.stdout.write('%s\n' % (cdll.LoadLibrary("libcrypt.so"),)) sys.stdout.write('%s\n' % (find_library("crypt"),))
Example #20
Source File: util.py From python-scripts with GNU General Public License v3.0 | 5 votes |
def test(): from ctypes import cdll if os.name == "nt": print(cdll.msvcrt) print(cdll.load("msvcrt")) print(find_library("msvcrt")) if os.name == "posix": # find and load_version print(find_library("m")) print(find_library("c")) print(find_library("bz2")) # getattr ## print cdll.m ## print cdll.bz2 # load if sys.platform == "darwin": print(cdll.LoadLibrary("libm.dylib")) print(cdll.LoadLibrary("libcrypto.dylib")) print(cdll.LoadLibrary("libSystem.dylib")) print(cdll.LoadLibrary("System.framework/System")) else: print(cdll.LoadLibrary("libm.so")) print(cdll.LoadLibrary("libcrypt.so")) print(find_library("crypt"))
Example #21
Source File: util.py From RevitBatchProcessor with GNU General Public License v3.0 | 5 votes |
def test(): from ctypes import cdll if os.name == "nt": print cdll.msvcrt print cdll.load("msvcrt") print find_library("msvcrt") if os.name == "posix": # find and load_version print find_library("m") print find_library("c") print find_library("bz2") # getattr ## print cdll.m ## print cdll.bz2 # load if sys.platform == "darwin": print cdll.LoadLibrary("libm.dylib") print cdll.LoadLibrary("libcrypto.dylib") print cdll.LoadLibrary("libSystem.dylib") print cdll.LoadLibrary("System.framework/System") else: print cdll.LoadLibrary("libm.so") print cdll.LoadLibrary("libcrypt.so") print find_library("crypt")
Example #22
Source File: train.py From Visual-Template-Free-Form-Parsing with GNU General Public License v3.0 | 5 votes |
def set_procname(newname): from ctypes import cdll, byref, create_string_buffer newname=os.fsencode(newname) libc = cdll.LoadLibrary('libc.so.6') #Loading a 3rd party library C buff = create_string_buffer(len(newname)+1) #Note: One larger than the name (man prctl says that) buff.value = newname #Null terminated string as it should be libc.prctl(15, byref(buff), 0, 0, 0) #Refer to "#define" of "/usr/include/linux/prctl.h" for the misterious value 16 & arg[3..5] are zero as the man page says.
Example #23
Source File: tools.py From yandex-disk-indicator with GNU General Public License v3.0 | 5 votes |
def setProcName(newname): """ Sets the executable name """ from ctypes import cdll, byref, create_string_buffer libc = cdll.LoadLibrary('libc.so.6') buff = create_string_buffer(len(newname) + 1) buff.value = bytes(newname, 'UTF8') libc.prctl(15, byref(buff), 0, 0, 0)
Example #24
Source File: util.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test(): from ctypes import cdll if os.name == "nt": print(cdll.msvcrt) print(cdll.load("msvcrt")) print(find_library("msvcrt")) if os.name == "posix": # find and load_version print(find_library("m")) print(find_library("c")) print(find_library("bz2")) # load if sys.platform == "darwin": print(cdll.LoadLibrary("libm.dylib")) print(cdll.LoadLibrary("libcrypto.dylib")) print(cdll.LoadLibrary("libSystem.dylib")) print(cdll.LoadLibrary("System.framework/System")) # issue-26439 - fix broken test call for AIX elif sys.platform.startswith("aix"): from ctypes import CDLL if sys.maxsize < 2**32: print(f"Using CDLL(name, os.RTLD_MEMBER): {CDLL('libc.a(shr.o)', os.RTLD_MEMBER)}") print(f"Using cdll.LoadLibrary(): {cdll.LoadLibrary('libc.a(shr.o)')}") # librpm.so is only available as 32-bit shared library print(find_library("rpm")) print(cdll.LoadLibrary("librpm.so")) else: print(f"Using CDLL(name, os.RTLD_MEMBER): {CDLL('libc.a(shr_64.o)', os.RTLD_MEMBER)}") print(f"Using cdll.LoadLibrary(): {cdll.LoadLibrary('libc.a(shr_64.o)')}") print(f"crypt\t:: {find_library('crypt')}") print(f"crypt\t:: {cdll.LoadLibrary(find_library('crypt'))}") print(f"crypto\t:: {find_library('crypto')}") print(f"crypto\t:: {cdll.LoadLibrary(find_library('crypto'))}") else: print(cdll.LoadLibrary("libm.so")) print(cdll.LoadLibrary("libcrypt.so")) print(find_library("crypt"))
Example #25
Source File: util.py From PokemonGo-DesktopMap with MIT License | 5 votes |
def test(): from ctypes import cdll if os.name == "nt": print cdll.msvcrt print cdll.load("msvcrt") print find_library("msvcrt") if os.name == "posix": # find and load_version print find_library("m") print find_library("c") print find_library("bz2") # getattr ## print cdll.m ## print cdll.bz2 # load if sys.platform == "darwin": print cdll.LoadLibrary("libm.dylib") print cdll.LoadLibrary("libcrypto.dylib") print cdll.LoadLibrary("libSystem.dylib") print cdll.LoadLibrary("System.framework/System") else: print cdll.LoadLibrary("libm.so") print cdll.LoadLibrary("libcrypt.so") print find_library("crypt")
Example #26
Source File: util.py From unity-python with MIT License | 5 votes |
def test(): from ctypes import cdll if os.name == "nt": print cdll.msvcrt print cdll.load("msvcrt") print find_library("msvcrt") if os.name == "posix": # find and load_version print find_library("m") print find_library("c") print find_library("bz2") # getattr ## print cdll.m ## print cdll.bz2 # load if sys.platform == "darwin": print cdll.LoadLibrary("libm.dylib") print cdll.LoadLibrary("libcrypto.dylib") print cdll.LoadLibrary("libSystem.dylib") print cdll.LoadLibrary("System.framework/System") else: print cdll.LoadLibrary("libm.so") print cdll.LoadLibrary("libcrypt.so") print find_library("crypt")
Example #27
Source File: util.py From android_universal with MIT License | 5 votes |
def test(): from ctypes import cdll if os.name == "nt": print(cdll.msvcrt) print(cdll.load("msvcrt")) print(find_library("msvcrt")) if os.name == "posix": # find and load_version print(find_library("m")) print(find_library("c")) print(find_library("bz2")) # load if sys.platform == "darwin": print(cdll.LoadLibrary("libm.dylib")) print(cdll.LoadLibrary("libcrypto.dylib")) print(cdll.LoadLibrary("libSystem.dylib")) print(cdll.LoadLibrary("System.framework/System")) # issue-26439 - fix broken test call for AIX elif sys.platform.startswith("aix"): from ctypes import CDLL if sys.maxsize < 2**32: print(f"Using CDLL(name, os.RTLD_MEMBER): {CDLL('libc.a(shr.o)', os.RTLD_MEMBER)}") print(f"Using cdll.LoadLibrary(): {cdll.LoadLibrary('libc.a(shr.o)')}") # librpm.so is only available as 32-bit shared library print(find_library("rpm")) print(cdll.LoadLibrary("librpm.so")) else: print(f"Using CDLL(name, os.RTLD_MEMBER): {CDLL('libc.a(shr_64.o)', os.RTLD_MEMBER)}") print(f"Using cdll.LoadLibrary(): {cdll.LoadLibrary('libc.a(shr_64.o)')}") print(f"crypt\t:: {find_library('crypt')}") print(f"crypt\t:: {cdll.LoadLibrary(find_library('crypt'))}") print(f"crypto\t:: {find_library('crypto')}") print(f"crypto\t:: {cdll.LoadLibrary(find_library('crypto'))}") else: print(cdll.LoadLibrary("libm.so")) print(cdll.LoadLibrary("libcrypt.so")) print(find_library("crypt"))
Example #28
Source File: util.py From canape with GNU General Public License v3.0 | 5 votes |
def test(): from ctypes import cdll if os.name == "nt": print cdll.msvcrt print cdll.load("msvcrt") print find_library("msvcrt") if os.name == "posix": # find and load_version print find_library("m") print find_library("c") print find_library("bz2") # getattr ## print cdll.m ## print cdll.bz2 # load if sys.platform == "darwin": print cdll.LoadLibrary("libm.dylib") print cdll.LoadLibrary("libcrypto.dylib") print cdll.LoadLibrary("libSystem.dylib") print cdll.LoadLibrary("System.framework/System") else: print cdll.LoadLibrary("libm.so") print cdll.LoadLibrary("libcrypt.so") print find_library("crypt")
Example #29
Source File: __init__.py From Dragonfire with MIT License | 5 votes |
def noalsaerr(): asound = cdll.LoadLibrary('libasound.so') asound.snd_lib_error_set_handler(c_error_handler) yield asound.snd_lib_error_set_handler(None)
Example #30
Source File: util.py From oss-ftp with MIT License | 5 votes |
def test(): from ctypes import cdll if os.name == "nt": print cdll.msvcrt print cdll.load("msvcrt") print find_library("msvcrt") if os.name == "posix": # find and load_version print find_library("m") print find_library("c") print find_library("bz2") # getattr ## print cdll.m ## print cdll.bz2 # load if sys.platform == "darwin": print cdll.LoadLibrary("libm.dylib") print cdll.LoadLibrary("libcrypto.dylib") print cdll.LoadLibrary("libSystem.dylib") print cdll.LoadLibrary("System.framework/System") else: print cdll.LoadLibrary("libm.so") print cdll.LoadLibrary("libcrypt.so") print find_library("crypt")