4

当我打电话时:

import pandas as pd

tensorflow_macos(对于 M1 芯片)

我得到:

ImportError                               Traceback (most recent call last)
~/tensorflow_macos_venv/lib/python3.8/site-packages/pandas/__init__.py in <module>
     28 try:
---> 29     from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib
     30 except ImportError as e:  # pragma: no cover

~/tensorflow_macos_venv/lib/python3.8/site-packages/pandas/_libs/__init__.py in <module>
     12 
---> 13 from pandas._libs.interval import Interval
     14 from pandas._libs.tslibs import (

ImportError: dlopen(/Users/ashkan/tensorflow_macos_venv/lib/python3.8/site-packages/pandas/_libs/interval.cpython-38-darwin.so, 2): no suitable image found.  Did find:
    /Users/ashkan/tensorflow_macos_venv/lib/python3.8/site-packages/pandas/_libs/interval.cpython-38-darwin.so: mach-o, but wrong architecture
    /Users/ashkan/tensorflow_macos_venv/lib/python3.8/site-packages/pandas/_libs/interval.cpython-38-darwin.so: mach-o, but wrong architecture

The above exception was the direct cause of the following exception:

ImportError                               Traceback (most recent call last)
<ipython-input-3-94f55571b0d6> in <module>
      1 import numpy as np
----> 2 import pandas as pd
      3 
      4 import matplotlib.pyplot as plt
      5 

~/tensorflow_macos_venv/lib/python3.8/site-packages/pandas/__init__.py in <module>
     31     # hack but overkill to use re
     32     module = str(e).replace("cannot import name ", "")
---> 33     raise ImportError(
     34         f"C extension: {module} not built. If you want to import "
     35         "pandas from the source directory, you may need to run "

ImportError: C extension: dlopen(/Users/ashkan/tensorflow_macos_venv/lib/python3.8/site-packages/pandas/_libs/interval.cpython-38-darwin.so, 2): no suitable image found.  Did find:
    /Users/ashkan/tensorflow_macos_venv/lib/python3.8/site-packages/pandas/_libs/interval.cpython-38-darwin.so: mach-o, but wrong architecture
    /Users/ashkan/tensorflow_macos_venv/lib/python3.8/site-packages/pandas/_libs/interval.cpython-38-darwin.so: mach-o, but wrong architecture not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --force' to build the C extensions first.
4

4 回答 4

6

我希望已经安装了 Xcode 命令行工具。如果没有,请安装它,然后按照步骤操作。

第 1 步:迷你锻造

从miniforge GitHub安装 miniforge for arm64 (Apple Silicon) 。Miniforge 支持安装为 Apple Silicon 本地编译的 python 包。

第二步:创建 Conda 环境

在 miniforge 安装之后和执行此步骤之前,不要忘记打开一个新会话或获取您的 .zshrc。

创建一个空的 Conda 环境,然后激活它并安装 python 3.8。以及所有需要的软件包。请注意这里不需要 numpy,因为 pandas 已经安装了它,但它会在最后一步被 Apple 提供的版本覆盖。

conda create --name mytf
conda activate mytf
conda install -y python==3.8.6
conda install -y pandas matplotlib scikit-learn jupyterlab

我已经测试过了。在这些步骤之后它将起作用。

于 2021-01-07T15:46:52.257 回答
1

如下一篇文章所示(https://github.com/apple/tensorflow_macos/issues/6),似乎解决方案是从 conda 安装 pandas,直到他们解决了这个问题。

安装熊猫:

conda install pandas

或者直接从源安装: https ://github.com/pandas-dev/pandas#installation-from-sources

于 2021-01-04T14:55:36.993 回答
0

请按照以下步骤操作 - Tensorflow 安装很重要

使用 miniforge 安装执行此操作 -

conda install numpy scipy scikit-learn pandas matplotlib seaborn
于 2021-11-21T03:16:49.077 回答
-1

使用 Anaconda 可视化 UI 安装到您创建的 conda 环境中。您只需选择您的环境并搜索 pandas。

于 2021-01-16T17:29:33.427 回答