Ask Your Question

Bug Python binding x64 / Windows 7

asked 2013-05-30 13:51:43 -0600

mikolune gravatar image

updated 2013-05-30 13:53:19 -0600

Hi community,

I compiled OpenCV 2.4.9 on x64 / Windows 7, with Visual Studio 2012.

To use the python binding I copied cv2.pyd in the proper place on the python path, and then got the following error upon import :

>>> import cv2
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (initcv2)

Here's what worked for me to correct the issue

In cv2.cpp I replaced:

extern "C" CV_EXPORTS void initcv2();


extern "C" __declspec(dllexport) void initcv2();

Of course, this works only for Windows.

Here's what I hoped would work, but did not

Trying to modify the definition of CV_EXPORTS: In cvdef.h, replace:

#if (defined WIN32 || defined _WIN32 || defined WINCE || defined __CYGWIN__) && defined CVAPI_EXPORTS


#if (defined WIN32 || defined _WIN32 || defined _WIN64 || defined WINCE || defined __CYGWIN__) && defined CVAPI_EXPORTS

So, what would be the proper way to correct this issue ?


edit retag flag offensive close merge delete


did you file a bug report ?

btw same issue happens for 32bit, too

berak gravatar imageberak ( 2013-05-30 14:05:34 -0600 )edit

Just filed the report.

mikolune gravatar imagemikolune ( 2013-05-30 15:53:01 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2013-05-30 14:54:05 -0600

berak gravatar image

updated 2013-05-30 15:10:23 -0600

hmm, i think, i found it. (getting the same err on 32bit/xp)

btw, "Of course, this works only for Windows." --> this is only about windows. no need to worry about other users

the other modules define CVAPI_EXPORTS (look above, how it's used), so CV_EXPORTS evaluates to __declspec(dllexport)

the python module does not define CVAPI_EXPORTS, but opencv_python_EXPORTS instead, so the preprocessor misses it, and cvinit() does not end up in the symboltable. ( --> "ImportError: dynamic module does not define init function (initcv2)")

my fix was, to change the malformed opencv_python_EXPORTS to CVAPI_EXPORTS in the preprocessor settings, but that's only marginally better that your solution

looks like some cmake-related bug to me, and it should be fixed there.

(sidenote, size of cv2.pyd changed from 894kb(built march,23) to 1261kb(now). whoa what might be in there ?

edit flag offensive delete link more


OK, thanks! I will file a bug report on that.

mikolune gravatar imagemikolune ( 2013-05-30 15:41:19 -0600 )edit

oh, yes. please do so !

berak gravatar imageberak ( 2013-05-30 15:44:48 -0600 )edit
Login/Signup to Answer

Question Tools


Asked: 2013-05-30 13:51:43 -0600

Seen: 633 times

Last updated: May 30 '13