简体   繁体   English

已安装模块但找不到 Brew 安装的共享库

[英]Module installed but can't find a shared library installed by Brew

I need to install a module pyzbar which depends on another called zbar.我需要安装一个模块 pyzbar,它依赖于另一个名为 zbar 的模块。 According to the pypi link I first need to install zbar via根据pypi链接,我首先需要通过安装zbar

brew install zbar

then install the pyzbar然后安装pyzbar

pip install pyzbar

Having done of that when trying to run a code based on importing specific part of the module, it gives an error.在尝试基于导入模块的特定部分运行代码时完成此操作后,会出现错误。

from pyzbar.pyzbar import decode

The error is ImportError: Unable to find zbar shared library错误是 ImportError: Unable to find zbar shared library

How to check where exactly is the issue coming from and how to resolve it?如何检查问题究竟来自哪里以及如何解决?

Here are steps I took after checking comments: 1- Tried finding libzbar file and some how link that to the path so that the pyzbar file zbar_library.py can find that.以下是我在检查评论后采取的步骤: 1- 尝试查找 libzbar 文件以及如何将其链接到路径,以便 pyzbar 文件 zbar_library.py 可以找到它。 The libzbar files were in this location /opt/homebrew/Cellar/zbar/0.23.90 installed by homebrew and not in usr/local/lib (which surprisingly no such directory exists on my mac). libzbar 文件位于此位置 /opt/homebrew/Cellar/zbar/0.23.90 由 homebrew 安装,而不是 usr/local/lib (令人惊讶的是,我的 mac 上不存在这样的目录)。 The way I added the location of zbar lib file to path was by我将zbar lib文件的位置添加到路径的方式是

export DYLD_LIBRARY_PATH=/opt/homebrew/lib

in the terminal while I'm in the conda environment on which my python is running.在终端中,而我在我的 python 正在运行的 conda 环境中。 Now when trying to run python while importing pyzbar it finds something and no longer give the "no shared lib found" error, but gives the following errors:现在,当尝试在导入 pyzbar 时运行 python 时,它会发现一些东西并且不再给出“未找到共享库”错误,而是给出以下错误:

  File "/Users/username/miniconda3/envs/my_env/lib/python3.7/site-packages/pyzbar/zbar_library.py", line 66, in load
    libzbar = cdll.LoadLibrary(path)
  File "/Users/username/miniconda3/envs/my_env/lib/python3.7/ctypes/__init__.py", line 442, in LoadLibrary
    return self._dlltype(name)
  File "/Users/username/miniconda3/envs/my_env/lib/python3.7/ctypes/__init__.py", line 364, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/opt/homebrew/lib/libzbar.dylib, 6): no suitable image found.  Did find:
    /opt/homebrew/lib/libzbar.dylib: mach-o, but wrong architecture
    /opt/homebrew/Cellar/zbar/0.23.90/lib/libzbar.0.dylib: mach-o, but wrong architecture
    /opt/homebrew/lib/libzbar.dylib: mach-o, but wrong architecture
    /opt/homebrew/Cellar/zbar/0.23.90/lib/libzbar.0.dylib: mach-o, but wrong architecture

You may have multiple python/pip versions that caused such issue.您可能有多个导致此类问题的 python/pip 版本。 To be sure about this, you can try为了确定这一点,您可以尝试

python3.9 -m pip install pyzbar

python3.9
from pyzbar.pyzbar import decode

If there are still any errors on import, please include a list of all installed pip packages by doing如果导入仍然有任何错误,请通过执行包含所有已安装的 pip 包的列表

pip freeze --all

Probably your operating system has two versions of python even if you have configured the path correctly your system installs the library in the default python and not in the version you want.即使您已正确配置路径,您的操作系统也可能有两个版本的 python 您的系统将库安装在默认 python 中,而不是您想要的版本中。

The default directory after installing python depends on your system.安装 python 后的默认目录取决于您的系统。

You can install directly specifying which version will receive the library:您可以直接安装指定哪个版本将接收库:

python3.9 -m pip install "package" python3.9 -m pip 安装“包”
python3.7 -m pip install "package" python3.7 -m pip 安装“包”
python2.7 -m pip install "package" python2.7 -m pip 安装“包”

It is always recommended to use a version manager, virtual environment that separates the versions and can be used individually始终建议使用版本管理器,将版本分开并且可以单独使用的虚拟环境

reference install package参考安装package

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

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