Homebrew-core: OpenCV 3.4.1 cannot be imported in python3

Created on 5 Mar 2018  路  10Comments  路  Source: Homebrew/homebrew-core

Please note we will close your issue without comment if you delete, do not read or do not fill out the issue checklist below and provide ALL the requested information. If you repeatedly fail to use the issue template, we will block you from ever submitting issues to Homebrew again.

  • [x] are reporting a bug others will be able to reproduce and not asking a question. If you're not sure or want to ask a question do so on our Discourse: https://discourse.brew.sh
  • [x] have a problem with brew install (or upgrade, reinstall) a single, official formula (not cask)? If it's a general brew problem please file this issue at Homebrew/brew: https://github.com/Homebrew/brew/issues/new. If it's a brew cask problem please file this issue at https://github.com/caskroom/homebrew-cask/issues/new. If it's a tap (e.g. Homebrew/homebrew-php) problem please file this issue at the tap.
  • [x] ran brew update and can still reproduce the problem?
  • [x] ran brew doctor, fixed all issues and can still reproduce the problem?
  • [ ] ran brew gist-logs <formula> (where <formula> is the name of the formula that failed) and included the output link?
  • [x] if brew gist-logs didn't work: ran brew config and brew doctor and included their output with your issue?
Details
  • Python => 3.6.4
  • OpenCV => 3.4.1
  • Operating System => macOS 10.13.3 (17D102)
Detailed description

I am no longer able to import opencv in python3 after upgrading opencv from 3.4.0 to 3.4.1 via brew upgrade.

Steps to reproduce
$ brew upgrade
...
$ python3
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/usr/local/lib/python3.6/site-packages/cv2.cpython-36m-darwin.so, 2): Library not loaded: /usr/local/opt/hdf5/lib/libhdf5.101.dylib
  Referenced from: /usr/local/Cellar/opencv/3.4.1_1/lib/libopencv_hdf.3.4.dylib
  Reason: image not found
Output from brew config
HOMEBREW_VERSION: 1.5.8
ORIGIN: https://github.com/Homebrew/brew
HEAD: 08f7e8c5887d1c654a1a5d5bc851a9c9d5a00371
Last commit: 2 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 725f14c1f6dd6a35d9b7f97bae658f1119f06e79
Core tap last commit: 19 minutes ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_MAKE_JOBS: 4
HOMEBREW_RUBY_WARNINGS: -W0
CPU: quad-core 64-bit broadwell
Homebrew Ruby: 2.3.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
Clang: 9.0 build 900
Git: 2.16.2 => /usr/local/bin/git
Curl: 7.54.0 => /usr/bin/curl
Perl: /usr/bin/perl
Python: /usr/local/bin/python => /usr/local/Cellar/python/3.6.4_3/Frameworks/Python.framework/Versions/3.6/bin/python3.6
Ruby: /usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
Java: 1.8.0_152, 1.8.0_144
macOS: 10.13.3-x86_64
Xcode: 9.2
CLT: 9.2.0.0.1.1510905681
X11: 2.7.11 => /opt/X11
Output from brew doctor
Your system is ready to brew.

All 10 comments

hi, I also face the same problems on OpenCV and python.
I try brew reinstall --build-from-source octave
and the hdf5 problem had been solved.
You might will face another problem as I faced: fail to load tesseract package.
please try:
brew install imagemagick
and
brew install tesseract

@C-002 Thanks.

I try brew reinstall octave and fix hdf5 problem.

By the way, Xcode Command Line Tools needs to update to latest version to fix the problem.

I fixed the problem myself by running brew reinstall --build-from-source opencv

But the bug still persists for users not doing this.

I was having this same issue. @drasbeck fix did it for me and its working again.

I hit the same ImportError when tying to import cv2 in either python 2 or 3. I did not need to rebuild to fix.

See the fix by @mjpieters in issue #24924. Namely, do both brew install hdf5 and brew install tesseract and then try your import again.

Although we all have found fixes, the bug still remains.

The fact that I probably don't need neither hdf5 nor tesseract to do my things is also an open point as I see it. Do we even need those dependencies? I'm not saying I don't need them, but I don't have them and OpenCV works for me.

@drasbeck In general we don't consider the fact that someone doesn't need a particular dependency to be a bug. That said, if you brew update && brew upgrade you'll see that this is now fixed in such a way that those dependencies aren't needed and can be uninstalled.

@ilovezfs: Thank you very much for the quick response and fix. =) I can confirm it works.

I agree on the dependencies question and that dependencies are not bugs. It just got me wondering, that I could build from source, and then would not need those packages. I'm not a dependency minimalist per se. =)

Side note: isn't brew update kind of redundant in brew update && brew upgrade now that brew upgradedoes update automatically?

@drasbeck you're welcome. Yes, it is redundant unless you've disabled auto update or you've already run update/install/upgrade/reinstall within the HOMEBREW_AUTO_UPDATE_SECS period (60 second default). So I just say both to avoid back and forth.

@ilovezfs As of opencv 3.4.1_2 -> 3.4.1_3 I am facing this import error again.

Once again I can do a brew reinstall --build-from-source opencv and ~20 minutes later I'm back in business.

Should I open a new issue?

Was this page helpful?
0 / 5 - 0 ratings