So I've been having this issue fairly consistently over different virtual environments I've created. This is my most recent instance. I created a Python 3.6 virtual environment for a project that uses OpenCV. I downloaded the relevant modules to my virtual environment, but whenever I try to import them in my code, I get the following error:
>>> import cv2 as cv
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
I've looked up this error before, and from my understanding, it has something to do with the directories Python is looking at when it is trying to import my modules. I checked sys.path
and I got the following:
>>> import sys
>>> sys.path
['', '/home/[username]/catkin_ws/devel/lib/python2.7/dist-packages', '/opt/ros/kinetic/lib/python2.7/dist-packages', '/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/home/[username]/ECE432_Proj/lib/python3.6/site-packages', '/home/[username]/.local/lib/python3.6/site-packages', '/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages']
So I'm guessing that the bolded parts are where the error is coming from. When I'm trying to import cv2
, it finds cv2.so
in a different folder, and tries to import that instead, with no success.
My question is this: how do I modify the sys.path
so that Python looks at the correct folders when it is trying to find the right module to import?