首页 > 解决方案 > 在 macOS Catalina 上使用 python 3.9 在虚拟环境中安装 opencv-python 时出错

问题描述

我正在尝试deeplearning使用 macOS Catalina 在我的 MacBook Pro 上设置一个名为 , 的虚拟环境,用于深度学习项目 :-)。

deeplearning我所做的虚拟环境中,pip install opencv-python但这会引发错误,我不明白......我该如何解决?我忽略了什么吗?

查看整个错误输出的最后一点,它似乎正在尝试将不同numpy版本与特定python版本匹配。Python 3.9不在其中。这是问题吗?我应该恢复到版本Python 3.8吗?

我安装python@3.9numpy使用brew.

谢谢

桑德

pip install opencv-python
Collecting opencv-python
  Using cached opencv-python-4.4.0.44.tar.gz (88.9 MB)
  Installing build dependencies ... error
  ERROR: Command errored out with exit status 1:
   command: /Users/swvanderlaan/.virtualenvs/deeplearning/bin/python /Users/swvanderlaan/.virtualenvs/deeplearning/lib/python3.9/site-packages/pip install --ignore-installed --no-user --prefix /private/var/folders/kc/c5rw4cb94c1c149gsm2ygfc00000gn/T/pip-build-env-mudxxq4k/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel scikit-build cmake pip 'numpy==1.11.3; python_version=='"'"'3.5'"'"'' 'numpy==1.13.3; python_version=='"'"'3.6'"'"'' 'numpy==1.14.5; python_version=='"'"'3.7'"'"'' 'numpy==1.17.3; python_version>='"'"'3.8'"'"''
       cwd: None
  Complete output (4098 lines):
  Ignoring numpy: markers 'python_version == "3.5"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.6"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.7"' don't match your environment

[由于字数限制,我无法发布所有内容。]

  ERROR: Command errored out with exit status 1: /Users/swvanderlaan/.virtualenvs/deeplearning/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/kc/c5rw4cb94c1c149gsm2ygfc00000gn/T/pip-install-we6wxt_t/numpy/setup.py'"'"'; __file__='"'"'/private/var/folders/kc/c5rw4cb94c1c149gsm2ygfc00000gn/T/pip-install-we6wxt_t/numpy/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/kc/c5rw4cb94c1c149gsm2ygfc00000gn/T/pip-record-wdchzme9/install-record.txt --single-version-externally-managed --prefix /private/var/folders/kc/c5rw4cb94c1c149gsm2ygfc00000gn/T/pip-build-env-mudxxq4k/overlay --compile --install-headers /private/var/folders/kc/c5rw4cb94c1c149gsm2ygfc00000gn/T/pip-build-env-mudxxq4k/overlay/include/site/python3.9/numpy Check the logs for full command output.
  ----------------------------------------
ERROR: Command errored out with exit status 1: /Users/swvanderlaan/.virtualenvs/deeplearning/bin/python /Users/swvanderlaan/.virtualenvs/deeplearning/lib/python3.9/site-packages/pip install --ignore-installed --no-user --prefix /private/var/folders/kc/c5rw4cb94c1c149gsm2ygfc00000gn/T/pip-build-env-mudxxq4k/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- setuptools wheel scikit-build cmake pip 'numpy==1.11.3; python_version=='"'"'3.5'"'"'' 'numpy==1.13.3; python_version=='"'"'3.6'"'"'' 'numpy==1.14.5; python_version=='"'"'3.7'"'"'' 'numpy==1.17.3; python_version>='"'"'3.8'"'"'' Check the logs for full command output.

并更新。这延伸到安装:scipyscikit-learn-scikit-image它们都依赖于numpy. 其中也安装了pip3 install numpy.

标签: pythonmacosnumpypipopencv-python

解决方案


问题是这Python 3.9只是一些旧的弱点,而且看起来没有可用于OpenCV. pip尝试从源代码编译它也是如此,这显然失败了,因为它有很多依赖项。

我建议您现在安装并在几周/几个月内Python 3.8升级到所有常用软件包都可以在.Python 3.9pip


推荐阅读