0

After updating Python in Visual Studio Code (VSC), I'm trying to run:

import pandas as pd

And getting the following error message:

Python 3.9.6 (default, Oct 18 2022, 12:41:40) 
[Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/at/Library/Python/3.9/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.9 from "/Library/Developer/CommandLineTools/usr/bin/python3"
  * The NumPy version is: "1.24.2"

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

Original error was: dlopen(/Users/at/Library/Python/3.9/lib/python/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so, 0x0002): tried: '/Users/at/Library/Python/3.9/lib/python/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/at/Library/Python/3.9/lib/python/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so' (no such file), '/Users/at/Library/Python/3.9/lib/python/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))

I tried re-installing python, numpy and pandas, but nothing is working :(

I'm expecting to be able to import pandas package successfully.

  • did you check ? – bluesmonk Mar 20 '23 at 13:03
  • What does "updating Python in Visual Studio Code" mean? What did you do? The issue is, in any case, that you're mixing and matching ARM and Intel architectures – you may have installed an Intel (x64) Python interpreter and it is attempting to use ARM libraries. – AKX Mar 20 '23 at 13:04

1 Answers1

0

mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')

You can read this issue.

Here gives two solutions:

arch -x86_64 pip install pandas

or remove the whole cache directory

pip cache info
MingJie-MSFT
  • 5,569
  • 1
  • 2
  • 13