我是 macOS Monterey (12.3.1) 的新手。我正在使用帶有 m1 芯片的新 MacBook Pro。我已經在我的系統中安裝了 python 3.10。我正在嘗試運行以下代碼:
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
在學習上述程式時出現以下錯誤。
---------------------------------------------------------------------------
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'))
這是我嘗試在 MacBook 上安裝 python 模塊時的輸出。
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)
uj5u.com熱心網友回復:
根據 ImportError 的詳細資訊,看起來這來自您的matplotlib是使用不兼容的架構構建的。這很可能與 M1 架構有關。看起來這個答案對你也有幫助。
為了以防萬一,我還在此訊息中共享該代碼塊。
python -m pip install cython
python -m pip install --no-binary :all: --no-use-pep517 numpy
brew install libjpeg
python -m pip install matplotlib
uj5u.com熱心網友回復:
我能夠通過使用洗掉所有 pip 包來解決我的 MacBook pro m1 上的問題
pip3 freeze | xargs pip3 uninstall -y
然后重新安裝所需的模塊。在我的情況下 matplotlib 使用
pip install matplotlib
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/469371.html
標籤:Python python-3.x 苹果系统 matplotlib 喀拉斯
