1
votes

I have three versions of python:

python (2.7.10, default systemwide version shipped with MacOS)

python2 (2.7.15, installed with brew)

python3 (3.6.5, installed with brew)

I installed opencv for python2 and python3 using pip2 and pip3, respectively. However, I have a matlab application (VOT-toolkit) which generates a command as: /usr/bin/python -c "import cv2" which fails since /usr/bin/python refers to the systemwide python version which does not have opencv installed.

Is there a way I can install opencv for the systemwide python version? (If possible, directly using pip without having to build from sources)

Thanks!

1
have you tried something like /usr/bin/python -m pip install opencv-python ? This runs the module pip for the selected python and installs the desired module - api55
Thanks! that worked. Though I had to prefix sudo to make the installation happen. - n.gaurav
Great, I will add it as an answer then - api55

1 Answers

1
votes

Probably your pip2 points to the newer installation. One can use the specific pip of the installation or one can invoke pip using python. I prefer the later, since this is 100% certain that it will be installed for the correct python installation. To do it, you only need the path to the python installation which you want to use and write the following code:

/path/to/python -m pip install package

or in your case:

/usr/bin/python -m pip install opencv-python

In some weird cases pip is not install and you can do (python >= 2.7.9 or 3.4):

/usr/bin/python -m ensurepip

You may need permission to use this command so you can do it with sudo or any other way to ensure the permissions are met.