简体   繁体   English

Python在导入cv2时立即被杀死

[英]Python is killed immediately when importing cv2

MacBook Air M1 w/ 16GB - Big Sur 11.2.2 - Python 3.8.8 MacBook Air M1 带 16GB - Big Sur 11.2.2 - Python 3.8.8

Using conda installed through Miniforge for ARM64, I just installed OpenCV using "conda install opencv".使用通过 Miniforge for ARM64 安装的 conda,我刚刚使用“conda install opencv”安装了 OpenCV。 "conda list" indicates OpenCV 4.5.1 is installed. “conda list”表示已安装 OpenCV 4.5.1。 If I simply go into python and "import cv2", I immediately get kicked out with a message: "zsh: killed python".如果我只是将 go 转换为 python 和“import cv2”,我会立即被踢出一条消息:“zsh:killed python”。 Having a hard time diagnosing the problem.很难诊断问题。 Doesn't appear to be an issue with RAM, as I have around 8GB free. RAM 似乎不是问题,因为我有大约 8GB 可用空间。 Any ideas?有任何想法吗?

Edit: as of now, you need to compile opencv from source for the m1 chip.编辑:到目前为止,您需要为 m1 芯片从源代码编译 opencv。 see my answer below for more details.有关更多详细信息,请参见下面的答案。

Conda is pain when it comes to macos.当谈到 macos 时,Conda 很痛苦。 (This is my opinion) (这是我的意见)

Try using pip install尝试使用 pip 安装

pip install opencv-python

If you want to use separate environment, I would recommend to use pipenv it is far better then conda.如果你想使用单独的环境,我建议使用 pipenv 它比 conda 好得多。 Install from here这里安装

# create env and install opencv
pipenv install opencv-python

# activate the shell
pipenv shell

Turns out that there just isn't a pre-compiled binary for the M1 chip yet.事实证明,M1 芯片还没有预编译的二进制文件。 So I think the version that conda installs is incompatible with this CPU.所以我认为conda安装的版本与这个CPU不兼容。 I ended up compiling it from source and that worked.我最终从源代码编译它并且有效。 Used guide from here:从这里使用的指南:

https://sayak.dev/install-opencv-m1/ https://sayak.dev/install-opencv-m1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM