Building static OpenCV with ffmpeg is still looking for shared libavcodec - python

I'm trying to build a static OpenCV Python with ffmpeg enabled to run on AWS Lambda. I Need to upload OpenCV my cv2.so in a zip file.
To do so I set the BUILD_SHARED_LIBS=OFF and WITH_FFPMEG=YES. But when doing import cv2 in the Python shell, I get the error:
ImportError: libavcodec.so.53: cannot open shared object file: No such file or directory
If I set WITH_FFPMEG=NO I don't get this error anymore but I need ffmpeg to read a video.
What I would like to do is OpenCV to use the static libavcodec library not the shared one. I thought setting up BUILD_SHARE_LIBS to off would be enough but it's not. T
here are no flags in the cmake file which let you specified the path to libavcodec. I've been looking for sometimes but I can't find a solution.
Any ideas?

Related

Can't import .so using ctypes in Python

Problem
I am trying to link C++ with python, so I compiled a .so file via g++ (the MinGW version, so I believe it should be able to run on Windows) and then in python:
import ctypes
lib = ctypes.cdll.LoadLibrary("support.so")
I get the Error:
FileNotFoundError: Could not find module 'support.so' (or one of its dependencies). Try using the full path with constructor syntax.
I tried using the full path and using os.add_dll_directory(), but didn't help.
Environment
Python 3.8 / 3.9 both not working
The .so file is created by myself, it is compiled via g++.
I encourtered this problem first on Windows 11, and solved it by changing the winmode in ctypes.__init__() by the help of this answer https://stackoverflow.com/a/64472088/9249608.
However, when I copy this program and the .so file to another computer with Window 10, I cannot solve this problem by any of the above methods. I even tried adding the folder to the PATH or copying this .so file to the python folder, but it still produces the error.
Is there any way that I can know exactly which paths are being searched? I see that there are many searching modes in ctypes.__init__() but I don't know how to output the corresponding searching paths.

Ctype - Could not find DLL dependencies

I am trying to use already existing C library "IMSApiCLib.dll" to communicate with external program.
Problem is that this library is using some Java sub-libraries. Before using this library I need to set "Java" path to correct (actual) folder (tested with Tester.exe provided with DLL)
So I have BAT file which prepare it and run Python script itself
cd C:\API\imsapi-clib-9.10.00-7-windows64\
set PATH=.;.\java\jre\bin;.\java\jre\bin\server;%PATH%
python C:\API\imsapi-clib-9.10.00-7-windows64\Connection.py
Connection.py:
DllPath = r"C:\API\imsapi-clib-9.10.00-7-windows64\IMSApiCLib.dll"
imsapi_clib= ctypes.windll.LoadLibrary(DllPath)
FileNotFoundError: Could not find module
'C:\API\imsapi-clib-9.10.00-7-windows64\IMSApiCLib.dll' (or one of
its dependencies). Try using the full path with constructor syntax.
It seems that added new JAVA path is not used when using ctypes.windll.LoadLibrary()
Any tips?

DLL load failed: The specified module could not be found PYTHON

I'm trying to import a module (UHD) into Python 2.7 from a network location. Whenever I do the import I get the following error:
ImportError: DLL load failed: The specified module could not be found
The initial import calls an init.py script that imports the other libraries. The first library import in the init script throws this error at the following line, which is also the first line of code within that file:
from . import libpyuhd as lib
libpyuhd is a .pyd file in the same directory as other files for this module.
The interesting thing is that I can import this fine from one computer (specifically the computer I built the module from source on) but when I try to run from another computer it fails.
The python executable is also stored at the network location along with the all the code I am trying to run. The only thing used in the build that isn't on the network drive is Visual Studio.
Does this error mean it can't find the .pyd file or that it can find the .pyd file but fails to import something from it?
Thank you.
I just solved this problem so may be able to help.
This ImportError: DLL load failed error meanslibpyuhd is not able to find a dependent library.
What is best is to install the Dependency Walker utility and open libpyuhd in that. It takes a few minutes to analyze all the stuff and will list all the dependent libraries and those that cannot be found comes up with a question mark.
In my case, it showed the boost python library to be missing, though I had already installed it. I just added the path to the missing library to PATH environment variable and valla! It works now.
[
I have encountered the same problem. I used Dependency Walker in order to search which were the missing dll.
I checked both : libpyuhd.pyd and uhd.dll.
By the way, the missing lib are hightlighted at the first level of hiearchy like in the snapshot :
snapshot
Then I copied the dlls directly into the same directory of libpyuhd.
dir structure
And then I copied the whole new UHD package directory into my site-package :
C:\Users\"YOUR_USER_NAME"\AppData\Local\Programs\Python\Python39\Lib\site-packages
I removed the PYTHONPATH from the environment variables and my PATH contains :
Path
PS 1: uhd.dll is also in this directory because I followed this documentation : https://files.ettus.com/manual/page_python.html
Ettus doc
PS 2 : I just finished a second installation on an other Laptop (windows 10); it's very import to copy/paste both uhd.dll and libusb-1.0.dll to the installed uhd directory (normally in the site-package dir).

Trouble with failing to build _tkinter after installing binary tcltk

I am running linux and python 2.7.14 I have successfully installed the binary version of tcltk. I installed it into the same directory as python27 such that the following directories were all added in the same folders, namely: include, lib, etc. The bits were not all found when I configured python again so when I checked the setup.py file it mentioned I could do the following, which I did:
make clean
./configure --with-tcltk-includes="-I/home2/bishopk2/python27/include" --
with-tcltk-libs="-L/home2/bishopk2/python27/lib/tcllib1.18 -ltclm.n -L/
home2/bishopk2/python27/lib/tklib0.6 -ltkm.n"
make TCLTK_INCLUDES="/home2/bishopk2/python27/include"
TCLTK_LIBS="/home2/bishopk2/python27/lib"
I have tried all permutations of this (i.e., with and without the tcllib1.18, ltclm.n, etc., etc.)
I am not sure the best way to share a config.log on stack overflow but here is a link:
https://www.pharmacoengineering.com/share-a-file/
(I made the pdf downloadable)
I had to save it as a pdf file so that it would upload to wordpress.
When I looked at it, I am not sure why the tcl.h file could not be found because when I:
find . -name "tcl.h"
It says that it is in my /home2/bishopk2/python27/include folder.
All of the libraries are there and it should be able to connect Tkinter with my tcl and tk libraries.
Any help would be greatly appreciated.
Best wishes,
Corey
tcllib and tklib and libraries of Tcl scripts.
To build tkinter you need to link to the binary shared object library (a .so file). This should be named libtcl8.6.so or something similar. It is not clear from your post that you realize tclM.N is a way of saying Major number, Minor number but you should put the numbers in for your installed version. So on my Debian based system I will provide --with-tcltk-includes=/usr/include/tcl8.6 --with-tcltk-libs=/usr/lib/x86_64-linux-gnu given your example. If you need to put in the library name then -ltk8.6 -ltcl8.6 (the linker drops the lib prefix from the filename.

Azure ML Python with Script Bundle cannot import module

In Azure ML, I'm trying to execute a Python module that needs to import the module pyxdameraulevenshtein (https://pypi.python.org/pypi/pyxDamerauLevenshtein).
I followed the usual way, which is to create a zip file and then import it; however for this specific module, it seems to never be able to find it. The error message is as usual:
ImportError: No module named 'pyxdameraulevenshtein'
Has anyone included this pyxdameraulevenshtein module in Azure ML with success ?
(I took the package from https://pypi.python.org/pypi/pyxDamerauLevenshtein.)
Thanks for any help you can provide,
PH
I viewed the pyxdameraulevenshtein module page, there are two packages you can download which include a wheel file for MacOS and a source code tar file. I don't think you can directly use the both on Azure ML, because the MacOS one is just a share library .so file for darwin which is not compatible with Azure ML, and the other you need to first compile it.
So my suggestion is as below for using pyxdameraulevenshtein.
First, compile the source code of pyxdameraulevenshtein to a DLL file on Windows, please refer to the document for Python 2/3 or search for doing this.
Write a Python script using the DLL you compiled to implement your needs, please refer to the SO thread How can I use a DLL file from Python? for how to use DLL from Python and refer to the Azure offical tutorial to write your Python script
Package your Python script and DLL file as a zip file, then to upload the zip file to use it in Execute Python script model of Azure ML.
Hope it helps.
Adding the path to pyxdameraulevenshtein to your system path should alleviate this issue. The script checks the system path that the python script is running on and doesn't know where else to look for anything other than the default packages. If your python script is in the same directory as the pyxdameraulevenshtein package in your ZIP file, this should do the trick. Because you are running this within Azure ML and can't be sure of the exact location of your script each time you run it, this solution should account for that.
import os
import sys
sys.path.append(os.path.join(os.getcwd(), 'pyxdameraulevenshtein'))
import pyxdameraulevenshtein

Categories

Resources