OpenCV error while testing C++ wrapper built - c++

I have been able to implement an algorithm in C++ (error level analysis algorithm for JPEG images) and I have also been able to compile a Python wrapper for the code using cython but at the time of testing it I am facing issues.
This is the Link to my previously asked question containing the source code and all relevant information regarding the following post.
I have created a wrapper function for my C++ code and built it using cython but at the time time of testing I a getting the following error:
Traceback (most recent call last):
File "Test.py", line 1, in <module>
import ela
ImportError: /home/shreyash/Desktop/New/ela.so: undefined symbol:_ZN2cv14createTrackbarERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_PiiPFviPvES9_
There seems to some problem with the createtrackbar symbol in the shared object file which is somehow undefined.

The problem was with configurations of the setup.py file , i just had to expicitly specify all the libraries being used by my opencv implementation.
After compiling with the help of cython it generated a shared object file
which had all the defined symbols.

Related

Getting no module named _internals error while using Bloomberg API

I am currently using Python 2.7 and my OS is Windows 7. While attempting to use the Bloomberg API I am getting this error:
Traceback (most recent call last):
File "datagrab.py", line 1, in <module>
import blpapi, time, json
File "C:\Python27\lib\blpapi\__init__.py", line 5, in <module>
from .internals import CorrelationId
File "C:\Python27\lib\blpapi\internals.py", line 50, in <module>
_internals = swig_import_helper()
File "C:\Python27\lib\blpapi\internals.py", line 42, in swig_import_helper
import _internals
ImportError: No module named _internals
I have set my path variable to point to blpapi3_64.dll and also updated my bloomberg terminal. I have also moved the local blpapi API to a different directory but still the problem exists.
I am kind of new to this API in general. So can someone please guide me?
Thank you in advance!
From your question is sounds like maybe you have tried this, but just outlining one possible solution from the README in the Python Supported Release release available here.
Note that many Python installations add the current directory to the
module search path. If the Python interpreter is invoked from the
installer directory, such a configuration will attempt to use the
(incomplete) local blpapi directory as a module. If the above
import line fails with the message Import Error: No module named
_internals, move to a different directory before invoking python.
I know this question is a bit stale, but in case people end up here like me. Do you have the C++ version of blpapi? it is a requirement for the python api as mentioned here: https://www.bloomberg.com/professional/support/api-library/
so download the C++ zip installer, extract somewhere, and then add it as an environment variable so that the python api can find it:
Environment variable name: BLPAPI_ROOT
Value: C:\blp\blpapi_cpp_3.8.18.1 (THIS IS WHERE MINE IS INSTALLED, YOUR VALUE HERE MAY BE DIFFERENT)
Hope that helps!

Python complaining that a SWIG module doesn't exists

Following the different tutorials on the web, I have tried to make a wrapper of a c++ class in python, using SWIG.
My class looks like this:
/*file libraryInstance.h*/
struct LibraryInstance
{
void init();
void terminate();
private:
std::shared_ptr<AnObject> m_spAnObject;
};
For python exposition, I made this .i file:
%module LibraryInstance
%{
#include "libraryInstance.h"
%}
%include "libraryInstance.h"
then I have executed the command swig -c++ -python -o ./src/libraryInstance_wrap.cpp ./src/libraryInstance.i
without any output errors, swig has generated two files, libraryInstance_wrap.cpp and LibraryInstance.py
Then I compile the c++ files, including the libraryInstance_wrap.cpp. All compiles fine and I get my library .so file.
when I look into the swig generated LibraryInstance.py, I can clearly see the class LibraryInstance:
cf. entire generated python wrapper here.
But when I launch the command python LibraryInstance.py, in the same directory as my .so I see this error output:
Traceback (most recent call last):
File "LibraryInstance.py", line 26, in <module>
_LibraryInstance = swig_import_helper()
File "LibraryInstance.py", line 18, in swig_import_helper
import _LibraryInstance
ImportError: No module named _LibraryInstance
And when I look in the code of LibraryInstance.py, it just looks as if there has been an exception ImportError thrown, the the module cannot be found by python. ( line 18 ).
Any idea what should I do to correct this ?
In SWIG documentation, paragraph 31.2.2 it is stated that the name of the library .so should be _NameOfTheModule.so
So I have renammed my library _LibraryInstance.so, instead of LibraryInstance.so... and now my module loads fine.

Building PyV8 (a C++/Python project) from source in Windows

How do you get started running (and debugging) a C++/Python combined project?
So far I've started with the basics:
Checking out the project from source (http://code.google.com/p/pyv8/source/checkout)
Copying a helloworld.py example into the directory with PyV8, so it can import PyV8.
This doesn't work, of course:
Traceback (most recent call last):
File "helloworld.py", line 4, in <module>
import PyV8
File "C:\Users\Default User\Documents\pyv8-read-only\PyV8.py", line 32, in
<module>
import _PyV8
ImportError: No module named _PyV8
The next step is probably to compile the cpp files and somehow make them available to Python as a library, but I'm not sure how to do that from the command line. There appears to be a VS project but I don't have Visual Studio.
(It would be way more awesome if anyone could also figure out how to debug both the C++ and Python parts in Eclipse)
Help! Thanks.

build python extension with boost build

I'm trying to use boost.python and build a python extension from c++.
My cpp file use a function named 'BZ2_bzopen' which is in the library 'libbz2' under standard path (/usr/lib/). However, when I try to build the extension using boost build following the instruction, I received an error said:
====== BEGIN OUTPUT ======
Traceback (most recent call last):
File "CrossTrade.py", line 11, in <module>
from custom_c import GoThroughFile
ImportError: /home/jliu/toolpak/custom_c.so: undefined symbol: BZ2_bzopen
EXIT STATUS: 1
====== END OUTPUT ======
This seems to me as an error comes from not linking to the library, which is almost the same as if I compile the cpp file without the '-lbz2' command.
Anyone could offer some help on solving it, please?
Maybe you did not link to libbz2? In that case, follow the instructions in http://www.boost.org/doc/libs/1_46_1/doc/html/bbv2/tutorial.html#bbv2.tutorial.prebuilt to see how to link to libraries.

Why can't I import the 'math' library when embedding python in c?

I'm using the example in python's 2.6 docs to begin a foray into embedding some python in C. The example C-code does not allow me to execute the following 1 line script:
import math
Using line:
./tmp.exe tmp foo bar
it complains
Traceback (most recent call last):
File "/home/rbroger1/scripts/tmp.py", line 1, in <module>
import math
ImportError: [...]/python/2.6.2/lib/python2.6/lib-dynload/math.so: undefined symbol: PyInt_FromLong
When I do nm on my generated binary (tmp.exe) it shows
0000000000420d30 T PyInt_FromLong
The function seems to be defined, so why can't the shared object find the function?
I'm using Python 2.6, and I successfully compiled and ran that same example code that you listed, without changing anything in the source.
$ gcc python.c -I/usr/include/python2.6/ /usr/lib/libpython2.6.so
$ ./a.out random randint 1 100
Result of call: 39
$ ./a.out random randint 1 100
Result of call: 57
I specifically chose the random module because it does have from math import log,... so it is certainly importing the math module as well.
Your issue is probably due to how you're linking; see this forum post for a similar issue someone else had. I can't find the links again, but it seems like there are some common issues when trying to link against Python's static library then importing modules that require a dynamic library.