I have a problem trying to import cv2 in python3 when I run it from my home folder...
luis@luis-Ubuntu:~$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so: undefined symbol: PyCObject_Type
>>>
but when I run python3 inside /usr/lib/python3/dist-packages or /usr/local/lib/python3.5/dist-packages path it works fine...
luis@luis-Ubuntu:~$ cd /usr/lib/python3/dist-packages
luis@luis-Ubuntu:/usr/lib/python3/dist-packages$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>>
I know this is related to include a path on the sys library, I added the export PYTHONPATH on my ~/.bashrc but didn't solve the problem...
export PYTHONPATH="/usr/local/lib/python3.5/dist-packages:$PYTHONPATH"
I also found that if I insert the path before importing cv2 it works but I need to do this on all scripts or every time I run python3 from a terminal...
luis@luis-Ubuntu:~$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so: undefined symbol: PyCObject_Type
>>> import sys
>>> sys.path.insert(0,'/usr/lib/python3/dist-packages')
>>> import cv2
>>>
but I want to fix this permanently, does anyone know how to solve this... btw... runs fine on python2...
print(sys.path)
inside Python? – hkchengrex