1

I am getting an architecture error while importing any package, i understand my Python might not be compatible, can't understand it. Current Python Version - 2.7.10

`MyMachine:desktop *********$ python pythonmath.py Traceback (most recent call last): File "pythonmath.py", line 1, in import math ImportError: dlopen(/Users/*********/anaconda/lib/python2.7/lib-dynload/math.so, 2): no suitable image found. Did find: /Users/**********/anaconda/lib/python2.7/lib-dynload/math.so: mach-o, but wrong architecture MyMachine:desktop ***********$ python pythonmath.py Traceback (most recent call last): File "pythonmath.py", line 1, in import math ImportError: dlopen(/Users/anaconda/lib/python2.7/lib-dynload/math.so, 2): no suitable image found. Did find: /Users/***********/anaconda/lib/python2.7/lib-dynload/math.so: mach-o, but wrong architecture

Karan Sharma
  • 21
  • 1
  • 1
  • 3

4 Answers4

3

Below steps resolved this problem for me.

  • Quit the terminal.
  • Go to Finder => Apps
  • Right Click on Terminal
  • Get Info
  • Check the checkbox Open using Rosetta

Now, open the terminal and try again.

PS: Rosetta allows Mac with M1 architecture to use apps built for Mac with Intel chip. Most of the times the reason behind most of the architecture problems is this chip compatibility reason only. So, 'Open using Rosetta' for terminal allows us to use Rosetta by default for such applications.

  • For those of us who don't use macs (very often) it would be worth adding what 'open using Rosetta' means. does that launch 32bit emulation? – 2e0byo Dec 03 '21 at 19:06
  • This answer is a useful addition given the recent switch from x64 to ARM (+1), but please do take care when answering old questions: it's usually a good idea to specifically address why a 6 year old question needs a new answer in the answer itself. – Jared Smith Dec 04 '21 at 12:39
1

you are mixing 32bit and 64bit versions of python. probably you installed 64bit python version on a 32bit computer. go on and uninstall python and reinstall it with the right configuration.

Soorena
  • 4,352
  • 5
  • 30
  • 42
1

This issue is most probably due to messed up python installation. You can try uninstalling python from your os (Take this answer for help How to uninstall Python 2.7 on a Mac OS X 10.6.4?)

And reinstall python. This worked for me.

mental_matrix
  • 560
  • 4
  • 7
0

I had a similar problem trying to install dask. I solved it following these steps:

1/ Check which version of python are installed (I have : mac os python 2.x and 3.x, anaconda 3.8, brew 3.9):

python -m pipenv.help

Python installations found:

  • 3.9.6: /opt/homebrew/bin/python3
  • 3.9.6: /opt/homebrew/bin/python3.9
  • 3.8.8: /opt/anaconda3/bin/python3
  • 3.8.8: /opt/anaconda3/bin/python3.8
  • 3.8.2: /usr/bin/python3
  • 2.7.16: /usr/bin/python2
  • 2.7.16: /usr/bin/python2.7

2/ Use pipenv to create a 3.8 virtual environment:

pipenv install --python '/opt/anaconda3/bin/python3'
pipenv install 'dask[complete]'

Note: by default, pipenv was using the 3.9 brew version of python to create the virtual environment - which caused the problem.

3/ Activate the virtual environment and use it:

pipenv shell
yann-h
  • 521
  • 4
  • 7