Home > Back-end >  Can't install some pythons modules and some python modules are showing incompatible in my macbo
Can't install some pythons modules and some python modules are showing incompatible in my macbo

Time:05-02

I am new to macOS Monterey(12.3.1). I am using a new MacBook pro with having an m1 chip. I have installed python 3.10 in my system. I am trying to run the following code:

from urllib.parse import urljoin
from bs4 import BeautifulSoup
import matplotlib.pyplot as plt
import tensorflow as tf
import pandas as pd
import numpy as np
import requests, re, random
from keras.preprocessing import text, sequence
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import LSTM
from keras.layers import Embedding
from keras.layers import Dropout
from keras.callbacks import TensorBoard
from itertools import chain
from pickle import load, dump
import os

I am getting the following error while learning the above program.

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Input In [1], in <cell line: 3>()
      1 from urllib.parse import urljoin
      2 from bs4 import BeautifulSoup
----> 3 import matplotlib.pyplot as plt
      4 import tensorflow as tf
      5 import pandas as pd

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/__init__.py:109, in <module>
    105 from packaging.version import parse as parse_version
    107 # cbook must import matplotlib only within function
    108 # definitions, so it is safe to import from it here.
--> 109 from . import _api, _version, cbook, docstring, rcsetup
    110 from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence
    111 from matplotlib.cbook import mplDeprecation  # deprecated

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/cbook/__init__.py:31, in <module>
     28 import numpy as np
     30 import matplotlib
---> 31 from matplotlib import _api, _c_internal_utils
     32 from matplotlib._api.deprecation import (
     33     MatplotlibDeprecationWarning, mplDeprecation)
     36 @_api.deprecated("3.4")
     37 def deprecated(*args, **kwargs):

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/_c_internal_utils.cpython-310-darwin.so, 0x0002): tried: '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/matplotlib/_c_internal_utils.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e'))

And here is the output when I try to install python modules on my MacBook.

mac@Mac-MacBook-Pro ML % pip3.10 install os  
ERROR: Could not find a version that satisfies the requirement os (from versions: none)
ERROR: No matching distribution found for os
mac@Mac-MacBook-Pro ML % pip3.10 install matplotlib
Requirement already satisfied: matplotlib in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (3.5.1)
Requirement already satisfied: cycler>=0.10 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from matplotlib) (0.11.0)
Requirement already satisfied: fonttools>=4.22.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from matplotlib) (4.31.1)
Requirement already satisfied: packaging>=20.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from matplotlib) (21.3)
Requirement already satisfied: pyparsing>=2.2.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from matplotlib) (3.0.7)
Requirement already satisfied: numpy>=1.17 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from matplotlib) (1.22.3)
Requirement already satisfied: pillow>=6.2.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from matplotlib) (9.0.1)
Requirement already satisfied: kiwisolver>=1.0.1 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from matplotlib) (1.4.0)
Requirement already satisfied: python-dateutil>=2.7 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from matplotlib) (2.8.2)
Requirement already satisfied: six>=1.5 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib) (1.16.0)

CodePudding user response:

Based on the details of the ImportError, looks like that is coming from your matplotlib is build with incompatible architecture. That is most likely related with M1 architecture. Looks like this answer can be helpful for you as well.

I am also sharing that code-block in this message just in case.

python -m pip install cython   
python -m pip install --no-binary :all: --no-use-pep517 numpy
brew install libjpeg
python -m pip install matplotlib

CodePudding user response:

I was able to fix the problem on my MacBook pro m1 by deleting all pip packages using

pip3 freeze | xargs pip3 uninstall -y

then reinstalling the required module. In my case matplotlib using

pip install matplotlib
  • Related