原因はPCをMacBook Air M1に変えましたが、Apple Silicon(ARMベース)のプロセッサを使用しているためらしいです。
OpenCV bindings requires "numpy" package.
Install it via command:
pip install numpy
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/__init__.py", line 23, in <module>
from . import multiarray
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/multiarray.py", line 10, in <module>
from . import overrides
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/overrides.py", line 6, in <module>
from numpy.core._multiarray_umath import (
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so: mach-o, but wrong architecture
/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so: mach-o, but wrong architecture
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/user/Dropbox/python/source_code/kindle2text/image_processing_utils.py", line 1, in <module>
import cv2
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/cv2/__init__.py", line 11, in <module>
import numpy
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/__init__.py", line 140, in <module>
from . import core
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/__init__.py", line 49, in <module>
raise ImportError(msg)
ImportError:
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:
Please note and check the following:
* The Python version is: Python3.10 from "/usr/local/bin/python3"
* The NumPy version is: "1.23.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(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so: mach-o, but wrong architecture
/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so: mach-o, but wrong architecture
・セキュリティソフトの影響
仮想環境をすすめられたので利用しようとします。
pyenv version
で表示されるバージョンが3.10.7でした。
そこで、以下のコマンドでバージョンを3.10.8に変えようとするとエラーが出ました。
pyenv local 3.10.8
/usr/local/Cellar/pyenv/2.3.5/libexec/pyenv-version-file-write: line 21: .python-version: Operation not permitted
MacBook Air M1はApple Silicon(ARMベース)のプロセッサを使用しています。そのため、特定のPythonライブラリをインストールする際には、x86_64アーキテクチャ用のものと異なるバイナリが必要な場合があります。以下は、MacBook Air M1でnumpyをインストールする方法です:
brew install python@3.10
Warning: You are using macOS 11.
We (and Apple) do not provide support for this old version.
It is expected behaviour that some formulae will fail to build in this old version.
It is expected behaviour that Homebrew will be buggy and slow.
Do not create any issues about this on Homebrew's GitHub repositories.
Do not create any issues even if you think this message is unrelated.
Any opened issues will be immediately closed without response.
Do not ask for help from Homebrew or its maintainers on social media.
You may ask for help in Homebrew's discussions but are unlikely to receive a response.
Try to figure out the problem yourself and submit a fix as a pull request.
We will review it but may or may not accept it.
git -C $(pyenv root) pull
fatal: not a git repository (or any of the parent directories): .git
どうやらbrewを使ってpyenvをインストールしていないためできないらしいです。
そのため、pyenvをアンイストールコマンドではなく、rmコマンドでアンイストールしました。
すると、
pyenv install --list | grep -E '^ [0-9]'
で、3.11.5などが表示されました。
そして、pyenvをインストールし直そうとしたら以下のエラーが出ました。
pyenv install 3.11.5
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.11.5.tar.xz...
-> https://www.python.org/ftp/python/3.11.5/Python-3.11.5.tar.xz
Installing Python-3.11.5...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
BUILD FAILED (OS X 11.7.10 using python-build 2.3.29)
chatGPTの回答は以下です。
このエラーは、Python 3.11.5 のソースコードが Apple Silicon (M1) の arm64 アーキテクチャに対応していない、または一部の依存関係が不足していることを示唆しています。
そのためbrewをアップグレードしようとしたが以下のエラーが出ました。
brew upgrade
Warning: You are using macOS 11.
We (and Apple) do not provide support for this old version.
It is expected behaviour that some formulae will fail to build in this old version.
It is expected behaviour that Homebrew will be buggy and slow.
Do not create any issues about this on Homebrew's GitHub repositories.
Do not create any issues even if you think this message is unrelated.
Any opened issues will be immediately closed without response.
Do not ask for help from Homebrew or its maintainers on social media.
You may ask for help in Homebrew's discussions but are unlikely to receive a response.
Try to figure out the problem yourself and submit a fix as a pull request.
We will review it but may or may not accept it.
pyenv install 3.11.6
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.11.6.tar.xz...
-> https://www.python.org/ftp/python/3.11.6/Python-3.11.6.tar.xz
Installing Python-3.11.6...
python-build: use readline from homebrew
BUILD FAILED (OS X 14.0 using python-build 20180424)
Inspect or clean up the working tree at /var/folders/50/dg88z33d52b50pmv_l9x3lbr0000gn/T/python-build.20231007092424.13394
Results logged to /var/folders/50/dg88z33d52b50pmv_l9x3lbr0000gn/T/python-build.20231007092424.13394.log
Last 10 log lines:
checking pkg-config is at least version 0.9.0... yes
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... "darwin"
checking for gcc... clang
checking whether the C compiler works... no
configure: error: in `/var/folders/50/dg88z33d52b50pmv_l9x3lbr0000gn/T/python-build.20231007092424.13394/Python-3.11.6':
configure: error: C compiler cannot create executables
See `config.log' for more details
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
pyenv install 3.11.6
python-build: use openssl from homebrew
python-build: use readline from homebrew
Downloading Python-3.11.6.tar.xz...
-> https://www.python.org/ftp/python/3.11.6/Python-3.11.6.tar.xz
Installing Python-3.11.6...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
BUILD FAILED (OS X 14.0 using python-build 2.3.29)
Inspect or clean up the working tree at /var/folders/50/dg88z33d52b50pmv_l9x3lbr0000gn/T/python-build.20231007093727.14474
Results logged to /var/folders/50/dg88z33d52b50pmv_l9x3lbr0000gn/T/python-build.20231007093727.14474.log
Last 10 log lines:
__locale_localeconv in _localemodule.o
__locale_localeconv in _localemodule.o
__locale_localeconv in _localemodule.o
__locale_localeconv in _localemodule.o
_libintl_textdomain, referenced from:
__locale_textdomain in _localemodule.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Programs/_freeze_module] Error 1
make: *** Waiting for unfinished jobs....
2 warnings generated.
pip3 install numpy
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: numpy in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (1.23.4)
以下のコマンドを実行します。
pip3.11 --version
pip 23.2.1 from /opt/homebrew/lib/python3.11/site-packages/pip (python 3.11)
pip3 --version
ERROR:root:code for hash blake2b was not found.
Traceback (most recent call last):
File "/Users/user/.pyenv/versions/3.11.6/lib/python3.11/hashlib.py", line 307, in <module>
globals()[__func_name] = __get_hash(__func_name)
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/.pyenv/versions/3.11.6/lib/python3.11/hashlib.py", line 129, in __get_openssl_constructor
return __get_builtin_constructor(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/.pyenv/versions/3.11.6/lib/python3.11/hashlib.py", line 123, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type blake2b
ERROR:root:code for hash blake2s was not found.
Traceback (most recent call last):
File "/Users/user/.pyenv/versions/3.11.6/lib/python3.11/hashlib.py", line 307, in <module>
globals()[__func_name] = __get_hash(__func_name)
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/.pyenv/versions/3.11.6/lib/python3.11/hashlib.py", line 129, in __get_openssl_constructor
return __get_builtin_constructor(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/user/.pyenv/versions/3.11.6/lib/python3.11/hashlib.py", line 123, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type blake2s
(中略)
ERROR:root:code for hash blake2b was not found.
Traceback (most recent call last):
File "/private/var/folders/50/dg88z33d52b50pmv_l9x3lbr0000gn/T/python-build.20231009212235.13038/Python-3.11.6/Lib/hashlib.py", line 307, in <module>
globals()[__func_name] = __get_hash(__func_name)
^^^^^^^^^^^^^^^^^^^^^^^
File "/private/var/folders/50/dg88z33d52b50pmv_l9x3lbr0000gn/T/python-build.20231009212235.13038/Python-3.11.6/Lib/hashlib.py", line 123, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type blake2b
ERROR:root:code for hash blake2s was not found.
Traceback (most recent call last):
File "/private/var/folders/50/dg88z33d52b50pmv_l9x3lbr0000gn/T/python-build.20231009212235.13038/Python-3.11.6/Lib/hashlib.py", line 307, in <module>
globals()[__func_name] = __get_hash(__func_name)
^^^^^^^^^^^^^^^^^^^^^^^
File "/private/var/folders/50/dg88z33d52b50pmv_l9x3lbr0000gn/T/python-build.20231009212235.13038/Python-3.11.6/Lib/hashlib.py", line 123, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type blake2s
Looking in links: /var/folders/50/dg88z33d52b50pmv_l9x3lbr0000gn/T/tmpvuk3jpy3
Processing /private/var/folders/50/dg88z33d52b50pmv_l9x3lbr0000gn/T/tmpvuk3jpy3/setuptools-65.5.0-py3-none-any.whl
Processing /private/var/folders/50/dg88z33d52b50pmv_l9x3lbr0000gn/T/tmpvuk3jpy3/pip-23.2.1-py3-none-any.whl
Installing collected packages: setuptools, pip
WARNING: The scripts pip3 and pip3.11 are installed in '/Users/user/.pyenv/versions/3.11.6/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-23.2.1 setuptools-65.5.0
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/user/.pyenv/versions/3.11.6/lib/python3.11/ssl.py", line 100, in <module>
import _ssl # if we can't import it, let the error propagate
^^^^^^^^^^^
ModuleNotFoundError: No module named '_ssl'
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?
Please consult to the Wiki page to fix the problem.
BUILD FAILED (OS X 14.0 using python-build 2.3.29)
Inspect or clean up the working tree at /var/folders/50/dg88z33d52b50pmv_l9x3lbr0000gn/T/python-build.20231009212235.13038
Results logged to /var/folders/50/dg88z33d52b50pmv_l9x3lbr0000gn/T/python-build.20231009212235.13038.log
Last 10 log lines:
File "/private/var/folders/50/dg88z33d52b50pmv_l9x3lbr0000gn/T/python-build.20231009212235.13038/Python-3.11.6/Lib/hashlib.py", line 123, in __get_builtin_constructor
raise ValueError('unsupported hash type ' + name)
ValueError: unsupported hash type blake2s
Looking in links: /var/folders/50/dg88z33d52b50pmv_l9x3lbr0000gn/T/tmpvuk3jpy3
Processing /private/var/folders/50/dg88z33d52b50pmv_l9x3lbr0000gn/T/tmpvuk3jpy3/setuptools-65.5.0-py3-none-any.whl
Processing /private/var/folders/50/dg88z33d52b50pmv_l9x3lbr0000gn/T/tmpvuk3jpy3/pip-23.2.1-py3-none-any.whl
Installing collected packages: setuptools, pip
WARNING: The scripts pip3 and pip3.11 are installed in '/Users/user/.pyenv/versions/3.11.6/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-23.2.1 setuptools-65.5.0