macports, python and some libs under Apple Silicon (M1)
This document is written in about Feb/6/2021. The library's situation may be changed when you reach here. I hope this document may help you.
1: Installing Macports
1) Download and install Xcode from AppStore. (about 1 hour is required.)
2) Open terminal (/Applications/other) and type "sudo xcode-select --install". Then a window comes up and you can click "install" => "agree".
3) type "sudo xcodebuild -license" => press return => press space, space .... => type "agree". => press return.
4) Download macports binary from https://www.macports.orrg/install.php, and install it.
2: Installing emacs
% sudo port -N install emacs
(Very simple)
3: Installing python38 & pip
1) Installing python38
% sudo port -N install python38
After installing...
% sudo port select --set python python38
% sudo port select --set python3 python38
Check python's path and its version are right.
% source ~/.zprofile
% which python
/opt/local/bin/python
% python --version
Python 3.8.7
% python3 --version
Python 3.8.7
2) Installing pip
% sudo port -N install py38-pip
% sudo port select --set pip pip38
% sudo port select --set pip3 pip38
% source ~/.zprofile
% which pip3
/opt/local/bin/pip3
% which pip
/opt/local/bin/pip
4: Installing numpy
% sudo -H python3 -m pip install numpy
Check whether install was succeed or not.
% python3 -c 'import numpy as np'
(Nothing is returned.)
5: Installing opencv-python (2021/06)
% sudo -H python3 -m pip install opencv-python
Collecting opencv-python
Using cached opencv-python-4.5.1.48.tar.gz (88.3 MB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing wheel metadata ... done
Requirement already satisfied: numpy>=1.17.3 in /opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from opencv-python) (1.20.1)
Building wheels for collected packages: opencv-python
Building wheel for opencv-python (PEP 517) ... done
Created wheel for opencv-python: filename=opencv_python-4.5.1.48-cp38-cp38-macosx_11_4_arm64.whl size=10638431 sha256=fb2afb14c2bd4b9ba17a428767cd04add4dccd453bfcaed5baad012f542d564a
Stored in directory: /private/var/root/Library/Caches/pip/wheels/b0/23/2e/cb78762f1aa90f5d4ab66bfbbb9e65b7d5b0476f06cc01dd0a
Successfully built opencv-python
Installing collected packages: opencv-python
Successfully installed opencv-python-4.5.1.48
WARNING: Running pip as root will break packages and permissions. You should install packages reliably by using venv: https://pip.pypa.io/warnings/venv
Install check
% python3 -c "import cv2;print(cv2.__version__);"
4.5.1
5: Installing opencv-python (old version)
% sudo port -N install cmake
% sudo port -N install OpenBLAS
(if you need) % sudo port install -N vtk
(if you need) % sudo port -N install ffmpeg (if you want)
% source ~/.zprofile
% git clone https://github.com/opencv/opencv.git
% git clone https://github.com/opencv/opencv_contrib.git
% cd opencv
% mkdir build
% cd build/
% cmake ../ \
-D CMAKE_SYSTEM_PRICESSOR=arm64 \
-D CMAKE_OSX_ARCHITECTURES=arm64 \
-D CMAKE_BUILD_TYPE=RELEASE \
-D WITH_IPP=OFF \
-D WITH_ITT=OFF \
-D WITH_PYTHON=ON \
-D BUILD_DOCS=ON \
-D BUILD_EXAMPLES=ON \
-D BUILD_opencv_python3=ON \
-D BUILD_opencv_python2=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OpenBLAS_LIB=/opt/local/lib/libopenblas-r1.a \
-D OpenBLAS_INCLUDE_DIR=/opt/local/include
% make
% sudo -H python3 -m pip install python_loader/
Install check
% sudo -H python3 -m pip list
Package Version
---------- -------
opencv 4.5.1
% python -c "import cv2; print( cv2.__version__ )"
4.5.1-dev
6: Installing jupyter-lab
% sudo -H python3 -m pip install jupyterlab
You have to add "/opt/local/Library/Frameworks/Python.framework/Versions/3.8/bin" to your PATH.
7: Pillow
% sudo -H python3 -m pip install Pillow
8: matplotlib
% sudo -H python3 -m pip install wheel
% sudo -H python3 -m pip install matplotlib
9: vtk & PyVista
% sudo port install clang-10
% sudo port select --set clang mp-clang-10
% sudo port select --set gcc mp-gcc-devel
%sudo port install ninja
% source ~/.zprofile
% cmake ../ -GNinja \
-DCMAKE_BUILD_TYPE=Release \
-DVTK_WHEEL_BUILD=ON \
-DVTK_PYTHON_VERSION=3 \
-DVTK_WRAP_PYTHON=ON \
-DPython3_EXECUTABLE=/opt/local/bin/python3
% ninja
% python3 setup.py bdist_wheel
% sudo -H python3 -m pip install dist/vtk-9.0.*_arm64.whl
Also you can install PyVista from now on.
% sudo -H python3 -m pip install pyvista
Reference: https://pyvista-doc.readthedocs.io/ja/latest/extras/building_vtk.html
10: coreutils
% sudo port install coreutils
You have to add "/opt/local/libexec/gnubin/" to your PATH.
この記事が気に入ったらサポートをしてみませんか?