1

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/

8
  • Does your environment PATH variable contain the "/usr/local/bin/" dir? Commented Nov 16, 2017 at 14:49
  • I have written 'export PATH=/usr/local/bin:$PATH' at my bash_profile and when I open '/etc/paths/' then '/usr/local/bin' is higher than 'usr/bin'. So what am I doing wrong? Commented Nov 16, 2017 at 14:54
  • You just said which python gives you not output, that means python executable is not present within directories listed in your PATH variable. So the order doesn't matter. Also on Step 4 why are you stating that python must necessarily be pointed at /usr/local/bin/python? Commented Nov 16, 2017 at 15:06
  • Ok, so how can I make it to be present within directories listed in my PATH variable please? Commented Nov 16, 2017 at 15:12
  • Python must point at /usr/local/bin/python because otherwise the virtual environment cannot be installed and specifically source /usr/local/bin/virtualenvwrapper.sh cannot be executed at the bash_profile. Also if python points at at /usr/local/bin/python then it means that I am using the system version and not the homebrew version. Commented Nov 16, 2017 at 15:15

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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!

Comments

0

Install OpenCV 'You must have Python3 installed'

pip3 install opencv-python

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.