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

时间:2021-07-13 21:35:47

标签: python pandas visual-studio-code apple-m1 pyenv

我买了 Mac M1,现在正在搭建我的 python 环境。

  • 我安装了 Rosetta 2,并将我的终端设置为 Rosetta 2
  • 我用 brew 安装了 pyenv
  • 使用 brew 安装 Sqlite3
  • 使用 pyenv 安装了 python 3.9.4(设置为全局)
  • 使用 brew 安装了 Visual Studio 代码
  • 最后,我在终端中使用“pip install pandas”安装了 pandas。

现在我在 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

我现在应该怎么做才能修复它?

2 个答案:

答案 0 :(得分:1)

删除后尝试重新安装pandas?

答案 1 :(得分:0)

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