[Python] Getting ImportError when importing Numpy into VSCode on a Mac

Discussão em 'Python' iniciado por Stack, Abril 30, 2025.

  1. Stack

    Stack Membro Participativo

    When I run import numpy on my Mac's VS Code environment, I get the following error. Can anyone help me navigate through this to resolve it? Pasting below the full traceback.

    >>> import numpy
    Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numpy/_core/__init__.py", line 23, in <module>
    from . import multiarray
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numpy/_core/multiarray.py", line 10, in <module>
    from . import overrides
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numpy/_core/overrides.py", line 8, in <module>
    from numpy._core._multiarray_umath import (
    add_docstring, _get_implementing_args, _ArrayFunctionDispatcher)
    ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numpy/_core/_multiarray_umath.cpython-313-darwin.so, 0x0002): tried: '/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numpy/_core/_multiarray_umath.cpython-313-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numpy/_core/_multiarray_umath.cpython-313-darwin.so' (no such file), '/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numpy/_core/_multiarray_umath.cpython-313-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64'))

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numpy/__init__.py", line 114, in <module>
    from numpy.__config__ import show as show_config
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numpy/__config__.py", line 4, in <module>
    from numpy._core._multiarray_umath import (
    ...<3 lines>...
    )
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numpy/_core/__init__.py", line 49, in <module>
    raise ImportError(msg)
    ImportError:

    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.13 from "/usr/local/bin/python3"
    * The NumPy version is: "2.1.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/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numpy/_core/_multiarray_umath.cpython-313-darwin.so, 0x0002): tried: '/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numpy/_core/_multiarray_umath.cpython-313-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numpy/_core/_multiarray_umath.cpython-313-darwin.so' (no such file), '/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numpy/_core/_multiarray_umath.cpython-313-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64'))


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

    Traceback (most recent call last):
    File "<python-input-0>", line 1, in <module>
    import numpy
    File "/Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/numpy/__init__.py", line 119, in <module>
    raise ImportError(msg) from e
    ImportError: Error importing numpy: you should not try to import numpy from
    its source directory; please exit the numpy source tree, and relaunch
    your python interpreter from there.

    Continue reading...

Compartilhe esta Página