Here are the steps you need to take in order to use mediapipe with Apple’s M1:
- Launch terminal using the Rosetta 2 translation layer. You can do this by opening Finder, going to
Applications > Utilities and right clicking Terminal. In the right-click menu, click on get-info and then tick the Open Using Rosetta checkbox.
-
Open a new Terminal window. (If terminal was previously opened, quit and relaunch it).
- Use the following command to install Homebrew for x86_64 architecture.
$arch -x86_64 /bin/bash -c (curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)
We do this because we’d like to install Python 3.8 for x86_64 where mediapipe is supported.
- Now that we have brew for x86_64, we can install Python 3.8 for x86_64 by running the command
arch -x86_64 /usr/local/homebrew/bin/brew install python@3.8
- This installation may take a while.Now that we have the Python version we need, we can create a new Virtual Environment. By using the command
arch -x86_64 /usr/local/homebrew/opt/python@3.8/bin/python3 -m venv myvenv
Remember, you need to specify your path to the x86_64 Python (the one we just installed). For me it was installed to /usr/local/homebrew/opt/python@3.8/bin/python3. For you it could be different. Either ways after Brew finishes installing Python, it’ll display the path it was installed to. You should see “Python was installed at /Path/to/newly/installed/python”. Also, the Virtual Environment will be created at ~/myvenv. You can change that by changing the myvenv part in the command.
- Start your Virtual Environment source
~/myvenv/bin/activate
I used this path ~/myvenv because thats where I created my Virtual Environment. If you created your Virtual Environment elsewhere, use that path.
- Now you should be inside the Virtual Environment, upgrade pip.
pip install --upgrade pip
-
Install mediapipe from pip, pip install mediapipe
- That’s it :) Now you can open your venv as a project in PyCharm for example. Specify the interpreter as the path of the x86_64 Python we just installed (Example /usr/local/homebrew/opt/python@3.8/bin/python3). Now you should be able to use mediapipe.