【问题标题】:Conda 3.9 is not working with numpy on macOS ("Reason: Image not found")?Conda 3.9 不能在 macOS 上使用 numpy(“原因:找不到图像”)?
【发布时间】:2021-02-24 16:15:49
【问题描述】:

我刚刚为conda 安装了一个python3.9 环境。它适用于基本 python,但显然不适用于numpy。错误是“原因:找不到图像”:

numpy安装成功:

conda install numpy


The following NEW packages will be INSTALLED:

  blas               conda-forge/osx-64::blas-2.106-openblas
  libblas            conda-forge/osx-64::libblas-3.9.0-6_openblas
  libcblas           conda-forge/osx-64::libcblas-3.9.0-6_openblas
  libgfortran        conda-forge/osx-64::libgfortran-5.0.0-9_3_0_h6c81a4c_18
  libgfortran5       conda-forge/osx-64::libgfortran5-9.3.0-h6c81a4c_18
  liblapack          conda-forge/osx-64::liblapack-3.9.0-6_openblas
  liblapacke         conda-forge/osx-64::liblapacke-3.9.0-6_openblas
  libopenblas        conda-forge/osx-64::libopenblas-0.3.12-openmp_h54245bb_1
  llvm-openmp        conda-forge/osx-64::llvm-openmp-11.0.1-h7c73e74_0
  numpy              pkgs/main/osx-64::numpy-1.19.2-py39h0fa1045_0
  numpy-base         pkgs/main/osx-64::numpy-base-1.19.2-py39h3a452eb_0


Proceed ([y]/n)? 

Preparing transaction: done
Verifying transaction: done
Executing transaction: done

安装conda install ipython也成功了。但是ipython 不起作用:

$ipython
Python 3.9.1 (default, Dec 11 2020, 06:28:49) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.20.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import numpy as np
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
~/miniconda3/envs/python39/lib/python3.9/site-packages/numpy/core/__init__.py in <module>
     21 try:
---> 22     from . import multiarray
     23 except ImportError as exc:

~/miniconda3/envs/python39/lib/python3.9/site-packages/numpy/core/multiarray.py in <module>
     11 
---> 12 from . import overrides
     13 from . import _multiarray_umath

~/miniconda3/envs/python39/lib/python3.9/site-packages/numpy/core/overrides.py in <module>
      6 
----> 7 from numpy.core._multiarray_umath import (
      8     add_docstring, implement_array_function, _get_implementing_args)


ImportError: dlopen(/Users/steve/miniconda3/envs/python39/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so, 2): Library not loaded: @rpath/libopenblas.dylib
  Referenced from: /Users/steve/miniconda3/envs/python39/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so
  Reason: image not found

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-1-0aa0b027fcb6> in <module>
----> 1 import numpy as np

~/miniconda3/envs/python39/lib/python3.9/site-packages/numpy/__init__.py in <module>
    138     from . import _distributor_init
    139 
--> 140     from . import core
    141     from .core import *
    142     from . import compat

~/miniconda3/envs/python39/lib/python3.9/site-packages/numpy/core/__init__.py in <module>
     46 """ % (sys.version_info[0], sys.version_info[1], sys.executable,
     47         __version__, exc)
---> 48     raise ImportError(msg)
     49 finally:
     50     for envkey in env_added:

ImportError: 

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.9 from "/Users/steve/miniconda3/envs/python39/bin/python"
  * The NumPy version is: "1.19.2"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: dlopen(/Users/steve/miniconda3/envs/python39/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so, 2): Library not loaded: @rpath/libopenblas.dylib
  Referenced from: /Users/steve/miniconda3/envs/python39/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so
  Reason: image not found

我在macOS Catalina

【问题讨论】:

  • 您是否阅读了错误消息中以IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE! 开头的部分?看起来它可能很重要。
  • @HåkenLid 是的,我做到了。 python 和 numpy 版本符合预期,我使用 vanilla conda install(不是来自源代码)
  • 尽量不要混合频道。即,确保它从 conda-forge 安装; conda install -c conda-forge conda-forge::numpy.
  • @merv 谢谢我会试试的
  • @merv 你真是个奇迹!请给出答案

标签: python numpy conda


【解决方案1】:

频道混合:不兼容的二进制文件

一个可能的问题是频道混合。不同的通道通常使用不同的构建堆栈,这可能导致在链接库中引用不同的符号。在这种情况下,请尝试确保所有内容都来自 conda-forge,例如

conda install -c conda-forge conda-forge::numpy

从长远来看,也许考虑将 conda-forge 添加到全局通道配置中,并可能将优先级设置为 "strict"。见conda config --describe channels channel_priority。此外,--env 标志可用于以特定环境的方式更改此类设置。

【讨论】:

  • 仅供此答案的读者参考:这是conda config的操作方法:$conda config --add channels conda-forge ( &gt; Warning: 'conda-forge' already in 'channels' list, moving to the top )
猜你喜欢
  • 2019-09-10
  • 2018-11-12
  • 2020-11-17
  • 2017-04-05
  • 2016-05-17
  • 2021-10-12
  • 2019-03-05
  • 2020-04-18
  • 2018-09-11
相关资源
最近更新 更多