user8801127
user8801127

Reputation:

How to install OpenCV+Python on Mac?

I am trying to install OpenCV+Python on Mac. I am trying to do this in six steps by running commands at terminal (after step2):

Step1: Install Xcode

Step2: Install Homebrew

Step3: Install Python2 and Python3

1) brew install python python3

2) brew linkapps python

brew linkapps python3

4) which python

which python3

Step4: Install Python libraries by installing a virtual environment

Step5: Install OpenCV

Step6: Symlink OpenCV+Python to virtual environment

The problem is that which python must give output /usr/local/bin/python and not /usr/bin/python as it gives by default so that the virtual environment can be installed to install then the Python libraries.

I removed the link by running unlink /usr/bin/python and I created a symlink by running ln -s /usr/local/Cellar/python /usr/bin/python (python and python3 are installed by default at /usr/local/Cellar/).

However now which python gives me no output even though I have created the symlink. Why is this?

How can I change the output of which command to install finally OpenCV+Python on Mac?

Any better idea to install OpenCV+Python on Mac with most of the useful libraries or virtual environments etc? (Obviously I know how to do the installation without all these)

P.S. I followed this link: https://www.learnopencv.com/install-opencv3-on-macos/

Upvotes: 1

Views: 2225

Answers (3)

Imam Ahasan
Imam Ahasan

Reputation: 1

Install OpenCV 'You must have Python3 installed'

pip3 install opencv-python

Upvotes: 0

Mike Lane
Mike Lane

Reputation: 1154

The officially recommended python packaging tool is pipenv. One example of a workflow you could use to make a virtual environment with the exact libraries your project needs as well as ensuring security is this:

$ brew install pipenv
$ cd /path/to/project
$ pipenv --three
$ pipenv install opencv-python

And after you write your code in, say, project.py

$ pipenv run python3 project.py

More info on the pipenv site.

Upvotes: 1

user8801127
user8801127

Reputation:

Finally, I did not solve the problem with which output even though I discuss it with really experienced people.

Finally, I downloaded PyCharm and I did the following:

1) Installed pip (Python package manager) by opening a project at PyCharm and going to PyCharm Community Edition (top bar) -> Preferences -> Project -> Project interpreter -> Press '+' -> Search and find pip (with the search bar) -> Press 'Install Package'

2) Type and enter pip install opencv-python (https://pypi.python.org/pypi/opencv-python) at the terminal

3) Follow the process at (1) to install/import opencv-python in PyCharm

4) Write import cv2 at the top of your source code

By not implementing the more extensive installation process described by the links that I posted above, I did not install the virtual environment which is highly recommended in order to avoid conflicts between various projects. But I think that I can make it without it for the moment!

Upvotes: 0

Related Questions