Python2 版本在版本检查中设置为 Python3



所以我试图按照本教程在MacOS上安装OpenCV:https://www.pyimagesearch.com/2016/12/19/install-opencv-3-on-macos-with-homebrew-the-easy-way/

在第 3 步中,python 的版本应该是 python 2.x 检查python --version和 python 3.y 检查python3 --version。但是在这两个命令上,我都得到了Python 3.6.4.我该如何解决这个问题?我尝试使用brew install python@2再次安装 python 2,输出python@2 2.7.14_1 is already installed.which python显示/usr/local/bin/python,而which python3显示/usr/local/bin/python3

如果您使用 Homebrew 安装了 Python 2 和 Python 3,则 Python 2 二进制文件名为python2,但除非您使用带有--force标志的brew link,否则不会链接到/usr/local中。

请参阅brew info python@2

$ brew info python@2 | grep Caveats -A 4
==> Caveats
This formula installs a python2 executable to /usr/local/opt/python@2/bin
If you wish to have this formula's python executable in your PATH then add
the following to ~/.bash_profile:
export PATH="/usr/local/opt/python@2/libexec/bin:$PATH"
$ brew info python@2 | grep 'not symlinked' -A 2
This formula is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

你可以运行

/usr/local/opt/python@2/bin/python2

如果您需要直接运行它,或者您可以强制Homebrew将其链接到:

brew link --force python@2

此时将添加/usr/local/bin/python2

本教程已经过时了;Homebrew如何处理Python已经发生了变化。只需在使用它python的地方使用python2即可。

要进一步解决本教程,请执行以下操作:

  • brew linkapps已弃用
  • homebrew/science分流器已弃用,该分流器中的公式已迁移,opencv3无需额外分流器即可安装。
  • 当前版本的opencv3原生支持 Python 2 和 3,无需配置开关
  • 公式直接依赖于 Python 2 和 3 公式,安装opencv3将自动安装 Python。

因此,只需运行brew install opencv3,按照命令打印的任何其他说明进行操作(可能没有)。

请确保更新Homebrew,因为缺少一些依赖项(请参阅我的Homebrew错误报告)。如果不这样做,则必须运行brew install hdf5 tesseract来安装应该是可选的依赖项。

本教程现在几乎完全过时了。

最新更新