Search code examples
pythonnumpypycharmapple-m1

Numpy fails in Pycharm but runs on VSCode/terminal M1 Mac


My code uses matplotlib which requires numpy. I'm using pipenv as my environment. When I run the code through my terminal and pipenv shell, it executes without a problem. I've just installed Pycharm for Apple silicon (I have an M1) and set up my interpreter to use the same pipenv environment that I configured earlier. However, when I try to run it through Pycharm (even the terminal in pycharm), it throws me the following error:

Original error was: dlopen(/Users/s/.local/share/virtualenvs/CS_156-UWxYg3KY/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so, 0x0002): tried: '/Users/s/.local/share/virtualenvs/CS_156-UWxYg3KY/lib/python3.8/site-packages/numpy/core/_multiarray_umath.cpython-38-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e'))

What's confusing me is the fact that my code executes when using this same environment through the my terminal... But it fails when running on Pycharm? Any insights appreciated!


Solution

  • The problem ended up being the python version I had installed. Since I upgraded from intel to M1, the python version also carried over. Downloading a new 3.10 version and creating a new interpreter for it solved this issue.