I'm following the guide found here:
http://www.dalkescientific.com/writings/NBN/c_extensions.html
for creating C extensions to python. But when I try to run any python program after building that module, such as the first one listed or mandelbrot.py (listed towards the end of the page). I get the error on the line libc = ctypes.CDLL("libc.dylib", ctypes.RTLD_GLOBAL)
The error is:
Traceback (most recent call last):
File "cos.py", line 5, in < module >
libc = ctypes.CDLL("libc.dylib", ctypes.RTLD_GLOBAL)
File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libc.dylib: cannot open shared object file: No such file or directory
I'm using Linux so I'm not sure if that is the problem. And if it is, how would I accomplish this on Linux? I know dll is how Windows refers to shared objects. But does the syntax change? I can't seem to find an answer anywhere.
On GNU/Linux the cos() function is located in a library called libm.so. So you need to replace "libc.dylib" with "libm.so".
Related
I installed OpenALPR itself fine and I was able to run it in terminal to get this result:
C:\Users\zebsu>"C:\\OpenALPR\\Agent\\bin\\alpr.exe" "C:\\plate.jpg"
plate0: 3 results
State ID: us-oh (97% confidence)
- PZ65BYV confidence: 94.5181 pattern_match: 0
- P265BYV confidence: 81.1941 pattern_match: 0
- P65BYV confidence: 81.1336 pattern_match: 0
However, I then followed the instructions found on PyPI (https://pypi.org/project/openalpr/#description) to install the openalpr python bindings with pip install openalpr. But when I run the following code that they suggest with python 3.8.6 x64:
import json
from openalpr import Alpr
alpr = Alpr("us", "C:/OpenALPR/Agent/etc/openalpr/openalpr.conf", "C:/OpenALPR/Agent/usr/share/openalpr/configruntime_data")
if not alpr.is_loaded():
print("Error loading OpenALPR")
sys.exit(1)
results = alpr.recognize_file("C:/image.jpg")
print(json.dumps(results, indent=4))
alpr.unload()
I get the following error:
Traceback (most recent call last):
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python38\lib\site-packages\openalpr\openalpr.py", line 70, in __init__
self._openalprpy_lib = ctypes.cdll.LoadLibrary("libopenalpr.dll")
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python38\lib\ctypes\__init__.py", line 451, in LoadLibrary
return self._dlltype(name)
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python38\lib\ctypes\__init__.py", line 373, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'libopenalpr.dll' (or one of its dependencies). Try using the full path with constructor syntax.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\zebsu\OneDrive\compuuter science\work\LPR\LPR_test.py", line 4, in <module>
alpr = Alpr("us", "C:/OpenALPR/Agent/etc/openalpr/openalpr.conf", "C:/OpenALPR/Agent/usr/share/openalpr/configruntime_data")
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python38\lib\site-packages\openalpr\openalpr.py", line 80, in __init__
raise nex
OSError: Unable to locate the OpenALPR library. Please make sure that OpenALPR is properly installed on your system and that the libraries are in the appropriate paths.
And this is the error that I get if I run the code with python 3.6.8 x32:
Traceback (most recent call last):
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openalpr\openalpr.py", line 70, in __init__
self._openalprpy_lib = ctypes.cdll.LoadLibrary("libopenalpr.dll")
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python36-32\lib\ctypes\__init__.py", line 426, in LoadLibrary
return self._dlltype(name)
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python36-32\lib\ctypes\__init__.py", line 348, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\zebsu\OneDrive\compuuter science\work\LPR\LPR_test.py", line 4, in <module>
alpr = Alpr("us", "C:/OpenALPR/Agent/etc/openalpr/openalpr.conf", "C:/OpenALPR/Agent/usr/share/openalpr/configruntime_data")
File "C:\Users\zebsu\AppData\Local\Programs\Python\Python36-32\lib\site-packages\openalpr\openalpr.py", line 80, in __init__
raise nex
OSError: Unable to locate the OpenALPR library. Please make sure that OpenALPR is properly installed on your system and that the libraries are in the appropriate paths.
I've scoured all the internet forums looking for answers however most of the submissions are from years back before the openalpr bindings could be installed with pip and had to be installed from github. Does anyone have any advice?
I ended up finding the solution from the answer to a question on another thread with a similar error but with a different library: FileNotFoundError: Could not find module 'libvlc.dll'. The issue was that the program had no way to find the dll files it needed so the directory where the dll files are needs to be added to the os in the python code. For me this meant adding these lines to the top of my code:
import os
os.add_dll_directory("C:/OpenALPR/Agent/bin")
This change meant that the code ran exactly as it was supposed to.
I know there are a lot of threads about the WinError 126 and so on. But I really need help...
I have a directory like this:
mytestscript.py
my32bit.dll
my64bit.dll
I have a 32 Bit and a 64 Bit Python Interpreter installed.
Now if I run mytestscript.py with a 32 Bit Interpreter, everything works fine.
import ctypes
dll = ctypes.windll.LoadLibrary("my32bit.dll")
print(dll)
But if i run it with a 64 Bit Interpreter
import ctypes
dll = ctypes.windll.LoadLibrary("my64bit.dll")
print(dll)
I get the follwoing error:
Traceback (most recent call last):
File "C:/Users/Heinzeri/Desktop/TEMPY/mytestscript.py", line 4, in <module>
dll = ctypes.windll.LoadLibrary("my64bit.dll")
File "C:\Program Files\Python37-64\Lib\ctypes\__init__.py", line 434, in LoadLibrary
return self._dlltype(name)
File "C:\Program Files\Python37-64\Lib\ctypes\__init__.py", line 356, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [Error 126] The specified module could not be found
What could be the cause that the 64-Bit Python doesn't find the DLL?
Do I have to add it to PATH / PYTHONPATH?
Do I need some Microsoft Redistributable?
The DLL's are checked 64bit and 32bit and come from a vendor.
This could also mean that another dependency is missing. Please use Dependencies (successor of Dependency Walker) to check what is happening behind the scenes.
Maybe some runtime for 64-bit is missing.
I am trying to create an executable of my Python application that uses PyGTK to make a GUI. I have a well-established, automated build process using Pyinstaller that has worked for me for a previous application. Suffice it to say that it calls the usual Makespec.py and Build.py with 32-bit Python 2.7, with Pyinstaller configured for 32 bits. The resulting 32-bit application works fine on my machine and another machine running Windows 7 64-bit, but fails on 32-bit Windows XP with this error:
C:\OutNav_0_64\OutNav_0.64>outnav
Traceback (most recent call last):
File "<string>", line 23, in <module>
File "C:\Pyinstaller-1.5\iu.py", line 436, in importHook
File "C:\Pyinstaller-1.5\iu.py", line 521, in doimport
File "C:\Users\462974\Documents\Local Sandbox\tools\utilities\Oni\build\pyi.win32\OutNav\outPYZ1.pyz/gtk", line 40, in
<module>
File "C:\Pyinstaller-1.5\iu.py", line 477, in importHook
File "C:\Pyinstaller-1.5\iu.py", line 495, in doimport
File "C:\Pyinstaller-1.5\iu.py", line 297, in getmod
File "C:\Pyinstaller-1.5\archive.py", line 468, in getmod
File "C:\Pyinstaller-1.5\iu.py", line 109, in getmod
ImportError: DLL load failed: The specified procedure could not be found.
The strange part is, there is no C:\Pyinstaller-1.5 directory on my machine or the one experiencing the error. I have no idea why it is attempting to run code from this nonexistent directory, or what the missing DLL is. Can anyone help me fold PyGTK into my application?
NOTE: The first line of the trace, line 23 in my program, is
import gtk
UPDATE: My manager successfully ran it on 64-bit Windows XP.
UPDATE 2: He was mistaken, it was 64-bit Windows 7. It has the same problem on his Windows XP installation.
Also, on the original machine it failed on, from the directory of the executable, I did this:
>>> import imp
>>> fp = open('gtk._gtk.pyd', 'rb')
>>> mod = imp.load_module('gtk._gtk', fp, 'gtk._gtk.pyd', ('.pyd', 'rb', 3))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed.
As far as I can tell, the .pyd file (which is in the format of a .DLL file) generated by pyinstaller on Windows 7 is incompatible with Windows XP. My solution was to simply recreate my build process on a Windows XP machine, which solved it to my satisfaction.
This is probably a simple problem. But I downloaded the pywiiuse library from here and I also downloaded the examples. However when I try to run one of the examples I end up with import issues. I'm not certain I have everything configured properly to run. One error I receive when trying to run example.py:
Press 1&2
Traceback (most recent call last):
File "example.py", line 73, in <module>
wiimotes = wiiuse.init(nmotes)
File "/home/thed0ctor/Descargas/wiiuse-0.12/wiiuse/__init__.py", line 309, in init
dll = ctypes.cdll.LoadLibrary('libwiiuse.so')
File "/usr/lib/python2.7/ctypes/__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python2.7/ctypes/__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libwiiuse.so: cannot open shared object file: No such file or directory
I'm really just starting out with this library and don't really see any documentation on how to configure pywiiuse so any help is much appreciated.
The pywiiuse library is a Python wrapper for the wiiuse C library.
Before you can use the wrapper you will first need to install the library it wraps, choose the newest version from this download page and download the appropriate installation package for you system (probably the .tar.gz since you appear to be on Linux).
add the link of libwiiuse.so to /usr/local/lib.
I also ran into this situation, I konw why it happies, but I don't konw the deep reason.
I have downloaded CVtypes and tried the example scripts with it but cannot get it working. The error I get is:
pete#pete-MacBookPro:~/python_scratch/cvtypes$ python showcam.py
Traceback (most recent call last):
File "showcam.py", line 1, in <module>
from CVtypes import cv
File "/home/pete/python_scratch/cvtypes/CVtypes.py", line 580, in <module>
_cxDLL = cdll.cxcore100
File "/usr/lib/python2.6/ctypes/__init__.py", line 423, in __getattr__
dll = self._dlltype(name)
File "/usr/lib/python2.6/ctypes/__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: cxcore100: cannot open shared object file: No such file or directory
I have installed all these packages for good measure which I thought would contain the required libs:
libcv-dev - development files for libcv
libcv2.1 - computer vision library
libcvaux-dev - development files for libcvaux
libcvaux2.1 - computer vision extension library
libhighgui-dev - development files for libhighgui
libhighgui2.1 - computer vision GUI library
opencv-doc - OpenCV documentation and examples
python-opencv - Python bindings for the computer vision library
Turns out CVtypes is ooooold. I needed PyOpenCV instead. As a Perl coder who is a newbie to Python I find the instability and deprecation a bit annoying.