python - 为 macosx 不兼容的库安装 opencv

标签 python macos opencv

我首先尝试使用无法导入 cv2 的自制软件 (macOS) 安装 OpenCV(错误:没有这样的模块)。然后我使用了 Anaconda,它给了我以下错误:

ImportError: dlopen(/Applications/anaconda/lib/python2.7/site- packages/cv2.so, 2): Library not loaded: @rpath/libhdf5.10.dylib Referenced from: /Applications/anaconda/lib/libopencv_hdf.3.1.0.dylib Reason: Incompatible library version: libopencv_hdf.3.1.dylib requires version 13.0.0 or later, but libhdf5.10.dylib provides version 12.0.0

关于如何修复此问题或完全重新安装的任何想法?

最佳答案

我遇到了同样的问题。获取新的 MacBook Pro 2017,然后安装 anaconda,并使用 conda (conda install -c conda-forge opencv) 安装 opencv。当试图运行包含

的 python 脚本时
import cv2 

我收到错误信息:

ImportError: dlopen(/anaconda2/lib/python2.7/site-packages/cv2.so, 2): Library not loaded: @rpath/libfreetype.6.dylib
  Referenced from: /anaconda2/lib/libopencv_freetype.3.4.dylib
  Reason: Incompatible library version: libopencv_freetype.3.4.dylib requires version 22.0.0 or later, but libfreetype.6.dylib provides version 21.0.0

我是这样解决的:

检查你的版本:

sudo find / -name libfreetype.6.dylib

我得到了:

/anaconda2/pkgs/freetype-2.8-h12048fb_1/lib/libfreetype.6.dylib
/anaconda2/lib/libfreetype.6.dylib

检查版本:

otool -L /anaconda2/pkgs/freetype-2.8-h12048fb_1/lib/libfreetype.6.dylib

我得到了:

@rpath/libfreetype.6.dylib (compatibility version 21.0.0, current version 21.0.0)

所以,我卸载了 anaconda:

rm -rf ~/anaconda2

同时从 anaconda 中删除所有备份

rm -rf ~/.anaconda

并编辑 .bash_profile 以删除任何 anaconda 路径

nano .bash_profile

https://www.continuum.io 安装了 anaconda

    installing: python-2.7.14-hde5916a_29 ...
Python 2.7.14 :: Anaconda, Inc.
installing: bzip2-1.0.6-hd86a083_4 ...
installing: ca-certificates-2017.08.26-ha1e5d58_0 ...
installing: conda-env-2.6.0-h36134e3_0 ...
installing: intel-openmp-2018.0.0-h8158457_8 ...
installing: jbig-2.1-h4d881f8_0 ...
installing: jpeg-9b-he5867d9_2 ...
installing: libcxxabi-4.0.1-hebd6815_0 ...
installing: libgfortran-3.0.1-h93005f0_2 ...
installing: libiconv-1.15-hdd342a3_7 ...
installing: libsodium-1.0.15-hd9e47c5_0 ...
installing: lzo-2.10-h362108e_2 ...
installing: pandoc-1.19.2.1-ha5e8f32_1 ...
installing: tk-8.6.7-h35a86e2_3 ...
installing: unixodbc-2.3.4-h4cb4dde_1 ...
installing: xz-5.2.3-h0278029_2 ...
installing: yaml-0.1.7-hc338f04_2 ...
installing: zlib-1.2.11-hf3cbc9b_2 ...
installing: libcxx-4.0.1-h579ed51_0 ...
installing: libpng-1.6.34-he12f830_0 ...
installing: mkl-2018.0.1-hfbd8650_4 ...
installing: openssl-1.0.2n-hdbc3d79_0 ...
installing: expat-2.2.5-hb8e80ba_0 ...
installing: freetype-2.8-h12048fb_1 ...
installing: gmp-6.1.2-hb37e062_1 ...
installing: hdf5-1.10.1-ha036c08_1 ...
installing: icu-58.2-h4b95b61_1 ...
installing: libffi-3.2.1-h475c297_4 ...
installing: libssh2-1.8.0-h322a93b_4 ...
installing: libtiff-4.0.9-h0dac147_0 ...
installing: ncurses-6.0-hd04f020_2 ...
installing: pcre-8.41-hfb6ab37_1 ...
installing: zeromq-4.2.2-ha360ad0_2 ...
installing: gettext-0.19.8.1-h15daf44_3 ...
installing: libcurl-7.58.0-hf30b1f0_0 ...
installing: libedit-3.1-hb4e282d_0 ...
installing: libxml2-2.9.7-hab757c2_0 ...
installing: mpfr-3.1.5-h711e7fd_2 ...
installing: readline-7.0-hc1231fa_4 ...
installing: curl-7.58.0-ha441bb4_0 ...
installing: glib-2.53.6-h33f6a65_2 ...
installing: libxslt-1.1.32-hb819dd2_0 ...
installing: mpc-1.0.3-h7a72875_5 ...
installing: sqlite-3.22.0-h3efe00b_0 ...
installing: dbus-1.12.2-h5243cc1_1 ...
installing: qt-5.6.2-h9975529_14 ...
installing: alabaster-0.7.10-py27h9dd7d6e_0 ...
installing: appnope-0.1.0-py27hb466136_0 ...
installing: appscript-1.0.1-py27h451298e_1 ...
installing: asn1crypto-0.24.0-py27_0 ...
installing: attrs-17.4.0-py27_0 ...
installing: backports-1.0-py27hb4f9756_1 ...
installing: backports_abc-0.5-py27h6972548_0 ...
installing: beautifulsoup4-4.6.0-py27h9416283_1 ...
installing: bitarray-0.8.1-py27h1de35cc_1 ...
installing: boto-2.48.0-py27hacdd0fd_1 ...
installing: cdecimal-2.3-py27h1de35cc_3 ...
installing: certifi-2018.1.18-py27_0 ...
installing: chardet-3.0.4-py27h2842e91_1 ...
installing: click-6.7-py27h2b86a94_0 ...
installing: cloudpickle-0.5.2-py27_1 ...
installing: colorama-0.3.9-py27hbbe92b6_0 ...
installing: configparser-3.5.0-py27hc7edf1b_0 ...
installing: contextlib2-0.5.5-py27h9cb85f4_0 ...
installing: dask-core-0.16.1-py27_0 ...
installing: decorator-4.2.1-py27_0 ...
installing: docutils-0.14-py27h0befae3_0 ...
installing: enum34-1.1.6-py27hf475452_1 ...
installing: et_xmlfile-1.0.1-py27hc42f929_0 ...
installing: fastcache-1.0.2-py27h1de35cc_2 ...
installing: filelock-2.0.13-py27h2c227fa_0 ...
installing: funcsigs-1.0.2-py27hb9f6266_0 ...
installing: functools32-3.2.3.2-py27h8ceab06_1 ...
installing: futures-3.2.0-py27h1b80678_0 ...
installing: glob2-0.6-py27h55c9705_0 ...
installing: gmpy2-2.0.8-py27h4bc979a_2 ...
installing: greenlet-0.4.12-py27h081ed54_0 ...
installing: grin-1.2.1-py27_4 ...
installing: heapdict-1.0.0-py27_2 ...
installing: idna-2.6-py27hedea723_1 ...
installing: imagesize-0.7.1-py27h4f7bcc8_0 ...
installing: ipaddress-1.0.19-py27_0 ...
installing: ipython_genutils-0.2.0-py27h8b9a179_0 ...
installing: itsdangerous-0.24-py27h3948ded_1 ...
installing: jdcal-1.3-py27hfeaf94f_0 ...
installing: lazy-object-proxy-1.3.1-py27h712ce3f_0 ...
installing: locket-0.2.0-py27ha10513d_1 ...
installing: lxml-4.1.1-py27hef8c89e_1 ...
installing: markupsafe-1.0-py27hd3c86fa_1 ...
installing: mccabe-0.6.1-py27h1f69e8d_0 ...
installing: mistune-0.8.3-py27_0 ...
installing: mkl-service-1.1.2-py27hcba3029_4 ...
installing: mpmath-1.0.0-py27h6b0eff6_2 ...
installing: msgpack-python-0.5.1-py27h04f5b5a_0 ...
installing: multipledispatch-0.4.9-py27h10993aa_0 ...
installing: numpy-1.14.0-py27h8a80b8c_1 ...
installing: olefile-0.45.1-py27_0 ...
installing: pandocfilters-1.4.2-py27hed78c4e_1 ...
installing: parso-0.1.1-py27he57c4c6_0 ...
installing: path.py-10.5-py27h0d68f8b_0 ...
installing: pep8-1.7.1-py27_0 ...
installing: pkginfo-1.4.1-py27ha9221e7_0 ...
installing: pluggy-0.6.0-py27had36429_0 ...
installing: ply-3.10-py27h6279b8a_0 ...
installing: psutil-5.4.3-py27h1de35cc_0 ...
installing: ptyprocess-0.5.2-py27h70f6364_0 ...
installing: py-1.5.2-py27he6783ac_0 ...
installing: pyaudio-0.2.7-py27h3777516_1 ...
installing: pycodestyle-2.3.1-py27h5b634e0_0 ...
installing: pycosat-0.6.3-py27h6c51c7e_0 ...
installing: pycparser-2.18-py27h0d28d88_1 ...
installing: pycrypto-2.6.1-py27h1de35cc_7 ...
installing: pycurl-7.43.0.1-py27hdbc3d79_0 ...
installing: pyodbc-4.0.22-py27h0a44026_0 ...
installing: pyparsing-2.2.0-py27h5bb6aaf_0 ...
installing: pysocks-1.6.7-py27h1cff6a6_1 ...
installing: python.app-2-py27hf2d5e94_7 ...
installing: pytz-2017.3-py27h803c07a_0 ...
installing: pyyaml-3.12-py27ha7932d0_1 ...
installing: pyzmq-16.0.3-py27h91ccc67_0 ...
installing: qtpy-1.3.1-py27h39159f8_0 ...
installing: rope-0.10.7-py27hffa1879_0 ...
installing: ruamel_yaml-0.15.35-py27h1de35cc_1 ...
installing: scandir-1.6-py27h97aa1ee_0 ...
installing: send2trash-1.4.2-py27_0 ...
installing: simplegeneric-0.8.1-py27_2 ...
installing: sip-4.18.1-py27h6300f65_2 ...
installing: six-1.11.0-py27h7252ba3_1 ...
installing: snowballstemmer-1.2.1-py27h68ac032_0 ...
installing: sortedcontainers-1.5.9-py27_0 ...
installing: sphinxcontrib-1.0-py27hd2ed746_1 ...
installing: sqlalchemy-1.2.1-py27h1de35cc_0 ...
installing: subprocess32-3.2.7-py27h24b2887_0 ...
installing: tblib-1.3.2-py27ha684fc4_0 ...
installing: toolz-0.9.0-py27_0 ...
installing: typing-3.6.2-py27h646fea0_0 ...
installing: unicodecsv-0.14.1-py27h170f95c_0 ...
installing: wcwidth-0.1.7-py27h817c265_0 ...
installing: webencodings-0.5.1-py27h19a9f58_1 ...
installing: werkzeug-0.14.1-py27_0 ...
installing: wrapt-1.10.11-py27hd341262_0 ...
installing: xlrd-1.1.0-py27hbd41ed1_1 ...
installing: xlsxwriter-1.0.2-py27h7f1064a_0 ...
installing: xlwt-1.2.0-py27hbeec4ae_0 ...
installing: babel-2.5.3-py27_0 ...
installing: backports.shutil_get_terminal_size-1.0.0-py27hc9115de_2 ...
installing: bottleneck-1.2.1-py27h71f98a3_0 ...
installing: cffi-1.11.4-py27h342bebf_0 ...
installing: conda-verify-2.0.0-py27hbebe81d_0 ...
installing: cycler-0.10.0-py27hfc73c78_0 ...
installing: cytoolz-0.9.0-py27h1de35cc_0 ...
installing: entrypoints-0.2.3-py27hd680fb1_2 ...
installing: h5py-2.7.1-py27h75626f5_0 ...
installing: html5lib-1.0.1-py27h5233db4_0 ...
installing: jedi-0.11.1-py27_0 ...
installing: llvmlite-0.21.0-py27hac8ee23_0 ...
installing: networkx-2.1-py27_0 ...
installing: nltk-3.2.5-py27h2e86947_0 ...
installing: numexpr-2.6.4-py27hf375000_0 ...
installing: openpyxl-2.4.10-py27_0 ...
installing: packaging-16.8-py27h24b219a_0 ...
installing: partd-0.3.8-py27h7560dbf_0 ...
installing: pathlib2-2.3.0-py27he09da1e_0 ...
installing: pexpect-4.3.1-py27_0 ...
installing: pillow-5.0.0-py27hfcce615_0 ...
installing: pyqt-5.6.0-py27hf21fe59_6 ...
installing: python-dateutil-2.6.1-py27hd56c96b_1 ...
installing: pywavelets-0.5.2-py27hd99e88a_0 ...
installing: qtawesome-0.4.4-py27hdeb2f59_0 ...
installing: scipy-1.0.0-py27h793f721_0 ...
installing: setuptools-38.4.0-py27_0 ...
installing: singledispatch-3.4.0.3-py27he22c18d_0 ...
installing: sortedcollections-0.5.3-py27h8094be4_0 ...
installing: sphinxcontrib-websupport-1.0.1-py27h857890b_1 ...
installing: ssl_match_hostname-3.5.0.1-py27h8780752_2 ...
installing: sympy-1.1.1-py27hce55102_0 ...
installing: traitlets-4.3.2-py27hcf08151_0 ...
installing: xlwings-0.11.5-py27_0 ...
installing: zict-0.1.3-py27h5fff8b1_0 ...
installing: backports.functools_lru_cache-1.4-py27h2aca819_1 ...
installing: bleach-2.1.2-py27_0 ...
installing: clyent-1.2.2-py27hc0ae608_0 ...
installing: cryptography-2.1.4-py27hdbc5e8f_0 ...
installing: cython-0.27.3-py27h6429b90_0 ...
installing: datashape-0.5.4-py27hd6a1745_0 ...
installing: get_terminal_size-1.0.0-h7520d66_0 ...
installing: gevent-1.2.2-py27hc02608c_0 ...
installing: imageio-2.2.0-py27h37746d9_0 ...
installing: isort-4.2.15-py27h5bf637f_0 ...
installing: jinja2-2.10-py27h70b8dc5_0 ...
installing: jsonschema-2.6.0-py27hd9b497e_0 ...
installing: jupyter_core-4.4.0-py27h5ea6ba4_0 ...
installing: navigator-updater-0.1.0-py27ha63e0b4_0 ...
installing: nose-1.3.7-py27h2ee3cb8_2 ...
installing: numba-0.36.2-np114py27he3a832a_0 ...
installing: pandas-0.22.0-py27h0a44026_0 ...
installing: patsy-0.5.0-py27_0 ...
installing: pickleshare-0.7.4-py27h37e3d41_0 ...
installing: pyflakes-1.6.0-py27h4446e76_0 ...
installing: pygments-2.2.0-py27h1a556bb_0 ...
installing: pytables-3.4.2-py27ha4551b8_2 ...
installing: pytest-3.3.2-py27_0 ...
installing: scikit-learn-0.19.1-py27h9788993_0 ...
installing: testpath-0.3.1-py27h72d81a5_0 ...
installing: tornado-4.5.3-py27_0 ...
installing: wheel-0.30.0-py27h677a027_1 ...
installing: astroid-1.6.1-py27_0 ...
installing: astropy-2.0.3-py27h1de35cc_0 ...
installing: bkcharts-0.2-py27haafc882_0 ...
installing: bokeh-0.12.13-py27h5233db4_0 ...
installing: distributed-1.20.2-py27_0 ...
installing: flask-0.12.2-py27h3ac5568_0 ...
installing: jupyter_client-5.2.2-py27_0 ...
installing: matplotlib-2.1.2-py27h6d6146d_0 ...
installing: nbformat-4.4.0-py27hddc86d0_0 ...
installing: pip-9.0.1-py27h1567d89_4 ...
installing: prompt_toolkit-1.0.15-py27h4a7b9c2_0 ...
installing: pyopenssl-17.5.0-py27hfda213f_0 ...
installing: statsmodels-0.8.0-py27h6d68dbf_0 ...
installing: terminado-0.8.1-py27_1 ...
installing: dask-0.16.1-py27_0 ...
installing: flask-cors-3.0.3-py27h13db576_0 ...
installing: ipython-5.4.1-py27_2 ...
installing: nbconvert-5.3.1-py27h6455e4c_0 ...
installing: pylint-1.8.2-py27_0 ...
installing: seaborn-0.8.1-py27h6bd0ddc_0 ...
installing: urllib3-1.22-py27hc3787e9_0 ...
installing: ipykernel-4.8.0-py27_0 ...
installing: odo-0.5.1-py27h992a9f7_0 ...
installing: requests-2.18.4-py27h9b2b37c_1 ...
installing: scikit-image-0.13.1-py27h1de35cc_1 ...
installing: anaconda-client-1.6.9-py27_0 ...
installing: blaze-0.11.3-py27hb49378a_0 ...
installing: jupyter_console-5.2.0-py27h9702a86_1 ...
installing: notebook-5.4.0-py27_0 ...
installing: qtconsole-4.3.1-py27hdc90b4f_0 ...
installing: sphinx-1.6.6-py27_0 ...
installing: anaconda-project-0.8.2-py27h2dc806c_0 ...
installing: jupyterlab_launcher-0.10.2-py27_0 ...
installing: numpydoc-0.7.0-py27h022f19e_0 ...
installing: widgetsnbextension-3.1.0-py27_0 ...
installing: anaconda-navigator-1.7.0-py27_0 ...
installing: ipywidgets-7.1.1-py27_0 ...
installing: jupyterlab-0.31.5-py27_0 ...
installing: spyder-3.2.6-py27_0 ...
installing: _ipyw_jlab_nb_ext_conf-0.1.0-py27h172cb35_0 ...
installing: jupyter-1.0.0-py27_4 ...
installing: anaconda-5.1.0-py27_2 ...
installing: conda-4.4.10-py27_0 ...
installing: conda-build-3.4.1-py27_0 ...
installation finished.

然后安装opencv:

conda install -c menpo opencv

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    tbb-4.3_20141023           |                0         1.6 MB  menpo
    opencv-2.4.11              |           py27_1         8.2 MB  menpo
    ------------------------------------------------------------
                                           Total:         9.8 MB

The following NEW packages will be INSTALLED:

    opencv: 2.4.11-py27_1  menpo
    tbb:    4.3_20141023-0 menpo

现在,它起作用了!

关于python - 为 macosx 不兼容的库安装 opencv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49119090/

相关文章:

python - 游标对象的 MySQL-Python 连接器属性错误

python - 在 Flask shell 中运行 Flask 应用程序时出现 AttributeError

python - Pyside 程序响应复选框单击而锁定

c++ - OpenCV训练错误(人脸识别)

python - 从 unicode 字符串中删除选定的标点符号

macos - 在 Mac OS X 上捆绑私有(private) JRE

objective-c - 如何像DVD播放机一样改变空间?

macos - 如何在 Emacs 中设置 CMD 键绑定(bind)?

c++ - OpenCV:对 cv::imwrite 的 undefined reference

python - 如何从文件夹(包括子文件夹)的图像创建 Numpy 数组