Similar problem over here. As others suggested, /opt/ros/kinetic/setup.bash
appends a path to ROS opencv in the PYTHONPATH
variable.
If you are working with multiple virtualenv
s and you need a solution that will work in most of the cases, then you can put the following code snippet in your .bashrc
:
source /opt/ros/kinetic/setup.bash
array=( $(find ~/.virtualenvs/ -mindepth 1 -maxdepth 1 -type d) )
for i in "${array[@]}"
do
export PYTHONPATH="$i/lib/python2.7/site-packages:$PYTHONPATH"
done
So the idea is that if you have a centralised directory of all of your virtualenv
s (e.g when you use virtualenvwrapper
) we can search for those directories using:
$(find ~/.virtualenvs/ -mindepth 1 -maxdepth 1 -type d)
given that all of our virtualenv
s are under ~/.virtualenvs
. This should give us a list of all of our virtualenv
s root directory.
We are then looping over the array of virtualenv directories and we are appending their path (e.g ~/.virtualenvs/testenv/lib/python2.7/site-packages
) to the PYTHONPATH
. Note that this should be done just after the source /opt/ros/kinetic/setup.bash
.
It's not a perfect solution to the problem as you can still get conflicts if two envs have different opencv versions, but for the initial problem, at least it should work.
Alternatively, you can just manually do the same trick for the desired virtualenv:
export PYTHONPATH=~/.virtualenvs/testenv/lib/python2.7/site-packages:$PYTHONPATH
ldd /opt/ros/kinetic/lib/python2.7/dist-packages/cv2.so
,echo $PYTHONPATH
, (in pythonconsole)import sys; print(sys.path)
, – Squirmy