numpy ImportError in VS Code (using virtualenvs) caused due to incompatible architecture
See original GitHub issueWhen I import a package that depends on numpy, the numpy import fails with the message below. Importing that same package outside VS Code works fine. I think this is some sort of subtle virtual environment activation error.
Environment
- macOS Monterey (12.3.1) on a MacBook Pro with an M1 chip
- VS Code 1.67.2
- I installed Python 3.10 from binary
This works outside VS Code
$ cd dev/pytables >>> go to the project director
$ workon pytables >>> activate the environment
from there I can:
$ python3 --version >>> 3.10.14
$ python3
>>> import src.pytables
and the import works.
Inside VS Code, the same thing fails
However, when if I do this instead:
$ code .
and then in a *.py at root level do the import and run (or debug) that file, it fails with this error:
Traceback (most recent call last): File “/Users/alecramsay/dev/pytables/sandbox.py”, line 13, in <module> from src.pytables import * File “/Users/alecramsay/dev/pytables/src/pytables/init.py”, line 3, in <module> from .t import * File “/Users/alecramsay/dev/pytables/src/pytables/t.py”, line 3, in <module> from .lang import * File “/Users/alecramsay/dev/pytables/src/pytables/lang.py”, line 10, in <module> from .program import * File “/Users/alecramsay/dev/pytables/src/pytables/program.py”, line 12, in <module> from .utils import * File “/Users/alecramsay/dev/pytables/src/pytables/utils.py”, line 8, in <module> import pandas as pd File “/Users/alecramsay/.virtualenvs/pytables/lib/python3.10/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.10 from “/Users/alecramsay/.virtualenvs/pytables/bin/python”
- The NumPy version is: “1.22.4”
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/alecramsay/.virtualenvs/pytables/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so, 0x0002): tried: ‘/Users/alecramsay/.virtualenvs/pytables/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so’ (mach-o file, but is an incompatible architecture (have ‘arm64’, need ‘x86_64’))
Both work if I make the virtual environment use Python 3.9 instead. I had to upgrade to 3.10 so another dependency would work.
Issue Analytics
- State:
- Created a year ago
- Comments:57 (3 by maintainers)
Top GitHub Comments
Oy! That, of course, solves the problem, @brettcannon . Cc @karrtikr .
I did not realize there were separate installs, and when I got a new M1-based Macbook, I set it up with my previous Time Machine image (all docs and applications). VS Code just came over with everything and, fwiw, generally worked/works just fine.
My sincere apologies for this long, winding troubleshooting and appreciate the help immensely.
As I said at the outset, I love VS Code and appreciate what you all have done as an insider might. Be well.
I figured out how to change the path to the virtual environment w/in VS Code. When I set it to:
~/.virtualenvs/pytables/bin/python3
the problem persists–exact same message from numpy (except it says that I’m using python3):
Again, that path outside VS Code works just fine.