简体   繁体   中英

MAC Python 3.8 IntelliJ error while importing panda module

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM