在使用 macOS ARM64 的 Python 3.10 上执行 `import cv2` 时出现 `Abort trap: 6` 错误

问题描述 投票:0回答:2

在使用 macOS ARM64 的 Python 3.10 上执行

Abort trap: 6
时出现以下
import cv2
错误。

我尝试使用较低版本的 opencv-python (4.6.0.66) 和最新版本,但仍然不起作用。我还尝试了一些修复,例如使用不同的终端和符号链接

libssl.dylib
libcrypto.dylib
/usr/local/lib

> python
Python 3.10.11 (main, May 22 2023, 00:42:58) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Modules/gcmodule.c:115: gc_decref: Assertion "gc_get_refs(g) > 0" failed: refcount is too small
Enable tracemalloc to get the memory block allocation traceback

object address  : 0x105a54010
object refcount : 8
object type     : 0x1056e3ab8
object type name: type
object repr     : <class 'cv2.utils.nested.ExportClassName'>

Fatal Python error: _PyObject_AssertFailed: _PyObject_AssertFailed
Python runtime state: initialized

Current thread 0x00000001fce51e00 (most recent call first):
Garbage-collecting
File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
File "<frozen importlib._bootstrap_external>", line 1176 in create_module
File "<frozen importlib._bootstrap>", line 571 in module_from_spec
File "<frozen importlib._bootstrap>", line 674 in _load_unlocked
File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
File "<frozen importlib._bootstrap>", line 1050 in _gcd_import
File "/opt/python/3.10.11/lib/python3.10/importlib/__init__.py", line 126 in import_module
File "/Users/alpha/Python/pv310-3di/lib/python3.10/site-packages/cv2/__init__.py", line 153 in bootstrap
File "/Users/alpha/Python/pv310-3di/lib/python3.10/site-packages/cv2/__init__.py", line 181 in <module>
File "<frozen importlib._bootstrap>", line 241 in _call_with_frames_removed
File "<frozen importlib._bootstrap_external>", line 883 in exec_module
File "<frozen importlib._bootstrap>", line 688 in _load_unlocked
File "<frozen importlib._bootstrap>", line 1006 in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1027 in _find_and_load
File "<stdin>", line 1 in <module>

Extension modules: numpy.core._multiarray_umath, numpy.core._multiarray_tests, numpy.linalg._umath_linalg, numpy.fft._pocketfft_internal, numpy.random._common, numpy.random.bit_generator, numpy.random._bounded_integers, numpy.random._mt19937, numpy.random.mtrand, numpy.random._philox, numpy.random._pcg64, numpy.random._sfc64, numpy.random._generator (total: 13)
Abort trap: 6
>
python macos opencv
2个回答
0
投票

所以我从OpenCV论坛找到了下面这篇文章:

Opencv 导致启用调试的 python 解释器因引用计数错误而中止

看起来(至少在我看来是在 macOS 上)使用

编译 Python

--with-pydebug

flag 导致错误,我在没有该 flag 的情况下重新编译 Python,它现在似乎工作正常......


0
投票

由于this,该错误是由适用于调试版本但不适用于发布版本的断言引起的。

当你使用 -O 标志启动 python 时,你可以轻松测试它

$ python -O
Python 3.11.9 (main, Apr  2 2024, 08:25:04) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>>

在 Python 文档中阅读有关启动标志的更多信息这里

© www.soinside.com 2019 - 2024. All rights reserved.