导入熊猫模块时Mac Python 3.8 Intellij错误

发布于 2025-01-21 02:56:12 字数 1554 浏览 1 评论 0原文

在我的Apple M1芯片机器上,尝试在IntelliJ IDEA中导入panda模块。运行该程序时出现以下错误。

如果我在命令行中运行相同的程序,它就可以工作。在IDE中运行时遇到这个问题。

有帮助解决此错误消息吗?

代码

import os
import pandas as pd

从此输出中删除我的主目录:

错误

Traceback (most recent call last):
  File "panda-test01.py", line 9, in <module>
    import pandas as pd
  File "Library/Python/3.8/lib/python/site-packages/pandas/__init__.py", line 16, in <module>
    raise ImportError(
ImportError: Unable to import required dependencies:
numpy: 

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.8 from "/Library/Developer/CommandLineTools/usr/bin/python3"
  * The NumPy version is: "1.22.3"

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

Original error was: dlopen(Library/Python/3.8/lib/python/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so, 0x0002): tried: 'Library/Python/3.8/lib/python/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))

谢谢

In my Apple M1 chip machine, trying to import panda module in IntelliJ IDEA. while running this program its giving below error.

If I run the same program in command line, it works. Running into this problem while running in the IDE.

Any help to resolve this error message?

Code

import os
import pandas as pd

Remove my home dir from this output:

Error

Traceback (most recent call last):
  File "panda-test01.py", line 9, in <module>
    import pandas as pd
  File "Library/Python/3.8/lib/python/site-packages/pandas/__init__.py", line 16, in <module>
    raise ImportError(
ImportError: Unable to import required dependencies:
numpy: 

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.8 from "/Library/Developer/CommandLineTools/usr/bin/python3"
  * The NumPy version is: "1.22.3"

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

Original error was: dlopen(Library/Python/3.8/lib/python/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so, 0x0002): tried: 'Library/Python/3.8/lib/python/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

定格我的天空 2025-01-28 02:56:12

从您的错误消息中:
(MACH-O文件,但是一个不兼容的架构(具有'arm64',需要'x86_64'))

这有点模棱两可,因为它可以解释,但我认为这意味着Intellij在x86模式下使用Rosetta2运行,而numpy/pandas安装python路径是您的手臂版本。 (替代方案是相反的,但是这种方式更有可能)。

为了运行程序,您需要创建一个使用Rosetta2并安装X86二进制文件而不是ARM的Python环境。我已经写了有关如何做到这一点的文章在这里作为我自己的参考。然后,Intellij应该在某个地方设置以指定用于执行和调试的Python环境,您应该将该环境/路径设置为新的X86环境。

from your error message:
(mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))

It's a little ambiguous as it could be interpreted either way round, but I think it means that IntelliJ is running using Rosetta2 in X86 mode, whereas the numpy/pandas installation the python PATH has is your arm version. (The alternative is the reverse of this, but this way round is more likely).

In order to run your program, you'll need to create a python environment which uses Rosetta2 and installs X86 binaries instead of arm. I've written about how to do this here as a reference for myself. Then IntelliJ should have a setting somewhere to specify the python environment to use for execution and debugging, you should set that environment/PATH to your new X86 environment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文