ImportError: dynamic module does not define module export function (PyInit_cv2)

心已入冬 提交于 2019-12-19 07:35:07

问题


When I try to import cv2 in IPython , I am getting this error-

ImportError: dynamic module does not define module export function (PyInit_cv2)

I have opencv 3.0, ubuntu 14.04, python 3.4.
I searched online but couldn't get any answer.


回答1:


Python3 libraries usually can be found in: /usr/lib/python3/dist-packages

I found out that the library cv2.cpython-34m.so is needed for Python3.4. But this file wasn't be contained in my default library directory.

In my environment, this library was stored in /usr/local/lib/python3.4/dist-packages/

So I created a symbolic link. Try it with:

cd /usr/lib/python3/dist-packages
sudo ln -s /usr/local/lib/python3.4/dist-packages/cv2.cpython-34m.so

python3
>>> import cv2

I hope, this helps you




回答2:


In my case, I was using opencv library for python2 in python3.

Check your PYTHONPATH by typing

echo $PYTHONPATH

and see there is correct path for python3.

$ echo $PYTHONPATH
:/usr/local/lib/python3.4/site-packages

I define PYTHONPATH at the end of ~/.bashrc file. Modify it if you are loading python2's library.

After source ~/.bashrc or restart terminal, check PYTHONPATH again

It solves my problem.



来源:https://stackoverflow.com/questions/36070215/importerror-dynamic-module-does-not-define-module-export-function-pyinit-cv2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!