如何解决 M1 Mac 中的导入 pandas 问题?

How to fix this import pandas problem in M1 Mac?

我买了 Mac M1,现在正在设置我的 python 环境。

现在我在 VS Code 中打开了一个 jypyter notebook 文件,并尝试将 pandas 导入为 pd, 然后它抛出了这个错误:

    ---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/var/folders/r5/wq0wq8mx0d56rbrbs38jt94w0000gn/T/ipykernel_10428/1362986570.py in <module>
----> 1 import pandas as pd

~/.pyenv/versions/3.9.4/lib/python3.9/site-packages/pandas/__init__.py in <module>
     20 
     21 # numpy compat
---> 22 from pandas.compat import (
     23     np_version_under1p18 as _np_version_under1p18,
     24     is_numpy_dev as _is_numpy_dev,

~/.pyenv/versions/3.9.4/lib/python3.9/site-packages/pandas/compat/__init__.py in <module>
     13 
     14 from pandas._typing import F
---> 15 from pandas.compat.numpy import (
     16     is_numpy_dev,
     17     np_array_datetime64_compat,

~/.pyenv/versions/3.9.4/lib/python3.9/site-packages/pandas/compat/numpy/__init__.py in <module>
      5 import numpy as np
      6 
----> 7 from pandas.util.version import Version
      8 
      9 # numpy versioning

~/.pyenv/versions/3.9.4/lib/python3.9/site-packages/pandas/util/__init__.py in <module>
----> 1 from pandas.util._decorators import (  # noqa
      2     Appender,
      3     Substitution,
      4     cache_readonly,
      5 )

~/.pyenv/versions/3.9.4/lib/python3.9/site-packages/pandas/util/_decorators.py in <module>
     12 import warnings
     13 
---> 14 from pandas._libs.properties import cache_readonly  # noqa
     15 from pandas._typing import F
     16 

~/.pyenv/versions/3.9.4/lib/python3.9/site-packages/pandas/_libs/__init__.py in <module>
     11 
     12 
---> 13 from pandas._libs.interval import Interval
     14 from pandas._libs.tslibs import (
     15     NaT,

ImportError: dlopen(/Users/yeung/.pyenv/versions/3.9.4/lib/python3.9/site-packages/pandas/_libs/interval.cpython-39-darwin.so, 2): no suitable image found.  Did find:
    /Users/yeung/.pyenv/versions/3.9.4/lib/python3.9/site-packages/pandas/_libs/interval.cpython-39-darwin.so: mach-o, but wrong architecture
    /Users/yeung/.pyenv/versions/3.9.4/lib/python3.9/site-packages/pandas/_libs/interval.cpython-39-darwin.so: mach-o, but wrong architecture

我现在应该怎么做才能解决它?

尝试在删除后重新安装 pandas?

也许 VSCode 是原生的(ARM 代码),所以它也会启动原生的 jupyter...尝试使用非 Rosetta 2 终端安装原生的 pandas 版本。