简体   繁体   English

ImportError: dlopen (Apple Silicon)

[英]ImportError: dlopen (Apple Silicon)

I am new to python, I was trying to import some libraries.我是 python 的新手,我正在尝试导入一些库。

import sys
import cv2
import face_recognition
import pickle

But, I get this error in VS Code.但是,我在 VS Code 中得到了这个错误。 When I run the same thing on PyCharm CE, It doesn't even recognize the module cv2.当我在 PyCharm CE 上运行相同的东西时,它甚至无法识别模块 cv2。 I know, I have installed opencv-python, but the issue still persists.我知道,我已经安装了 opencv-python,但问题仍然存在。

Traceback (most recent call last):
  File "/Users/vedantamohapatra/Downloads/Face Detection/embedding.py", line 3, in <module>
    import face_recognition
  File "/opt/homebrew/lib/python3.9/site-packages/face_recognition/__init__.py", line 7, in <module>
    from .api import load_image_file, face_locations, batch_face_locations, face_landmarks, face_encodings, compare_faces, face_distance
  File "/opt/homebrew/lib/python3.9/site-packages/face_recognition/api.py", line 4, in <module>
    import dlib
  File "/opt/homebrew/lib/python3.9/site-packages/dlib/__init__.py", line 19, in <module>
    from _dlib_pybind11 import *
ImportError: dlopen(/opt/homebrew/lib/python3.9/site-packages/_dlib_pybind11.cpython-39-darwin.so, 0x0002): tried: '/opt/homebrew/lib/python3.9/site-packages/_dlib_pybind11.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/_dlib_pybind11.cpython-39-darwin.so' (no such file), '/usr/lib/_dlib_pybind11.cpython-39-darwin.so' (no such file)

I tried searching for this error but didn't find any working solution.我尝试搜索此错误,但没有找到任何可行的解决方案。 Is this something which can't be solved now due to the architecture?由于架构,这是现在无法解决的问题吗? As I got a (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')) error in there too.因为我也有一个(mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e'))错误。 I am using M1 Mac Monterey 12.1.我正在使用 M1 Mac Monterey 12.1。 On a side node, If this issue is unresolved, can anyone please point out any alternative for this, like would Google Colab be fine?在一个侧面节点上,如果这个问题没有得到解决,任何人都可以指出任何替代方案,比如谷歌 Colab 会好吗?

I am having the same issue....Can someone help???我有同样的问题....有人可以帮忙吗??? Unable to move forward.无法前进。

File "/opt/homebrew/lib/python3.9/site-packages/face_recognition/api.py", line 4, in import dlib File "/opt/homebrew/lib/python3.9/site-packages/dlib/ init .py", line 19, in from _dlib_pybind11 import * ImportError: dlopen(/opt/homebrew/lib/python3.9/site-packages/_dlib_pybind11.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace '_png_do_expand_palette_rgb8_neon'文件“/opt/homebrew/lib/python3.9/site-packages/face_recognition/api.py”,第 4 行,在导入 dlib 文件“ /opt/homebrew/lib/python3.9/site-packages/dlib/init .py",第 19 行,从 _dlib_pybind11 导入 * ImportError: dlopen(/opt/homebrew/lib/python3.9/site-packages/_dlib_pybind11.cpython-39-darwin.so, 0x0002):在平面命名空间中找不到符号'_png_do_expand_palette_rgb8_neon'

I am not sure if this would work for your system too but this is what worked for me.我不确定这是否也适用于您的系统,但这对我有用。 I had PyCharm installed so I used its default Python Package installer located at the bottom left of the window and then added the required packages.我安装了PyCharm ,所以我使用了它的默认 Python Package 安装程序位于 Z05B8 的左下方,然后添加了所需的 C74CBD902FBF244 包。 This method not only solved the issue of the code not running in PyCharm but my code ran in the terminal too.这种方法不仅解决了代码在 PyCharm 中没有运行的问题,而且我的代码也在终端中运行了。

I think this might be due to conflicting Python versions installed in the Mac and the Terminal Package installer is installing it in different directory that which is used by the compiler during execution.我认为这可能是由于安装在 Mac 中的 Python 版本冲突,并且终端 Package 安装程序将其安装在编译器在执行期间使用的不同目录中。 This might be due to improper transition from Python 2 to Python 3 in Mac I feel.这可能是由于我感觉在 Mac 中从Python 2Python 3的不正确过渡。

If I find a more general fix to this I will update the answer.如果我找到更一般的解决方法,我会更新答案。

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

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