question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

numpy ImportError in VS Code (using virtualenvs) caused due to incompatible architecture

See original GitHub issue

When 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:closed
  • Created a year ago
  • Comments:57 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
alecramsaycommented, Aug 3, 2022

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.

1reaction
alecramsaycommented, Jul 28, 2022

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):

Please note and check the following:

  * The Python version is: Python3.10 from "/Users/alecramsay/.virtualenvs/pytables/bin/python3"
  * The NumPy version is: "1.22.4"

Again, that path outside VS Code works just fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

python - Importing the numpy C-extensions fails when ...
Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was...
Read more >
Troubleshooting ImportError — NumPy v1.24 Manual
The best thing to do if you see this error is to contact the maintainers of the package that is causing problem so...
Read more >
M1 mac: mach-o file, but is an incompatible architecture (have ...
I use conda from miniforge for python packages etc. This works. This means that I don't know first hand how pypi works, I...
Read more >
Changelog — Python 3.11.1 documentation
gh-98433: The IDNA codec decoder used on DNS hostnames by socket or asyncio ... gh-99370: Fix zip path for venv created from a...
Read more >
pipenv Documentation
Makefile, direct calls to pip and python -m venv or virtualenv. to ... The virtualenv name created by Pipenv may be different from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found