Cannot pip install mediapipe on Macos M1
Asked Answered
R

7

5

enter image description here

Hello fellows

I'm using mac air with M1 chip

My env sets like

(CV)  san  ~/work/python
 conda list
# packages in environment at /Users/san/miniforge3/envs/CV:
#
# Name                    Version                   Build  Channel
appnope                   0.1.2                    pypi_0    pypi
argon2-cffi               20.1.0                   pypi_0    pypi
async-generator           1.10                     pypi_0    pypi
attrs                     21.2.0                   pypi_0    pypi
backcall                  0.2.0                    pypi_0    pypi
bleach                    3.3.1                    pypi_0    pypi
ca-certificates           2021.5.30            h4653dfc_0    conda-forge
certifi                   2021.5.30        py38h10201cd_0    conda-forge
cffi                      1.14.6           py38h0957451_0    conda-forge
charset-normalizer        2.0.3                    pypi_0    pypi
cycler                    0.10.0                   pypi_0    pypi
debugpy                   1.4.0                    pypi_0    pypi
decorator                 5.0.9                    pypi_0    pypi
defusedxml                0.7.1                    pypi_0    pypi
entrypoints               0.3                      pypi_0    pypi
freetype                  2.10.4               h17b34a0_1    conda-forge
future                    0.18.2           py38h10201cd_3    conda-forge
idna                      3.2                      pypi_0    pypi
ipykernel                 6.0.3                    pypi_0    pypi
ipython                   7.25.0                   pypi_0    pypi
ipython-genutils          0.2.0                    pypi_0    pypi
ipywidgets                7.6.3                    pypi_0    pypi
jbig                      2.1               h3422bc3_2003    conda-forge
jedi                      0.18.0                   pypi_0    pypi
jinja2                    3.0.1                    pypi_0    pypi
joblib                    1.0.1              pyhd8ed1ab_0    conda-forge
jpeg                      9d                   h27ca646_0    conda-forge
jsonschema                3.2.0                    pypi_0    pypi
jupyter                   1.0.0                    pypi_0    pypi
jupyter-client            6.1.12                   pypi_0    pypi
jupyter-console           6.4.0                    pypi_0    pypi
jupyter-core              4.7.1                    pypi_0    pypi
jupyterlab-pygments       0.1.2                    pypi_0    pypi
jupyterlab-widgets        1.0.0                    pypi_0    pypi
kiwisolver                1.3.1                    pypi_0    pypi
lcms2                     2.12                 had6a04f_0    conda-forge
lerc                      2.2.1                h9f76cd9_0    conda-forge
libblas                   3.9.0                9_openblas    conda-forge
libcblas                  3.9.0                9_openblas    conda-forge
libcxx                    12.0.1               h168391b_0    conda-forge
libdeflate                1.7                  h27ca646_5    conda-forge
libffi                    3.3                  h9f76cd9_2    conda-forge
libgfortran               5.0.0.dev0      11_0_1_hf114ba7_22    conda-forge
libgfortran5              11.0.1.dev0         hf114ba7_22    conda-forge
liblapack                 3.9.0                9_openblas    conda-forge
libopenblas               0.3.15          openmp_hf330de4_1    conda-forge
libpng                    1.6.37               hf7e6567_2    conda-forge
libprotobuf               3.16.0               hccf11d3_0    conda-forge
libtiff                   4.3.0                hc6122e1_1    conda-forge
libwebp-base              1.2.0                h27ca646_2    conda-forge
llvm-openmp               12.0.1               hf3c4609_0    conda-forge
lz4-c                     1.9.3                h9f76cd9_0    conda-forge
markupsafe                2.0.1                    pypi_0    pypi
matplotlib                3.4.2                    pypi_0    pypi
matplotlib-inline         0.1.2                    pypi_0    pypi
mistune                   0.8.4                    pypi_0    pypi
nbclient                  0.5.3                    pypi_0    pypi
nbconvert                 6.1.0                    pypi_0    pypi
nbformat                  5.1.3                    pypi_0    pypi
ncurses                   6.2                  h9aa5885_4    conda-forge
nest-asyncio              1.5.1                    pypi_0    pypi
ninja                     1.10.2               h4d860bb_0    conda-forge
notebook                  6.4.0                    pypi_0    pypi
numpy                     1.18.5                   pypi_0    pypi
olefile                   0.46               pyh9f0ad1d_1    conda-forge
openjpeg                  2.4.0                h062765e_1    conda-forge
openssl                   1.1.1k               h27ca646_0    conda-forge
packaging                 21.0                     pypi_0    pypi
pandocfilters             1.4.3                    pypi_0    pypi
parso                     0.8.2                    pypi_0    pypi
pexpect                   4.8.0                    pypi_0    pypi
pickleshare               0.7.5                    pypi_0    pypi
pillow                    8.3.1            py38h02acf36_0    conda-forge
pip                       21.1.3             pyhd8ed1ab_0    conda-forge
prometheus-client         0.11.0                   pypi_0    pypi
prompt-toolkit            3.0.19                   pypi_0    pypi
ptyprocess                0.7.0                    pypi_0    pypi
pycparser                 2.20               pyh9f0ad1d_2    conda-forge
pygments                  2.9.0                    pypi_0    pypi
pyparsing                 2.4.7                    pypi_0    pypi
pyrsistent                0.18.0                   pypi_0    pypi
python                    3.8.6           h12cc5a1_5_cpython    conda-forge
python-dateutil           2.8.2                    pypi_0    pypi
python_abi                3.8                      2_cp38    conda-forge
pytorch                   1.8.0           cpu_py38h15dfef8_2    conda-forge
pyzmq                     22.1.0                   pypi_0    pypi
qtconsole                 5.1.1                    pypi_0    pypi
qtpy                      1.9.0                    pypi_0    pypi
readline                  8.1                  hedafd6a_0    conda-forge
requests                  2.26.0                   pypi_0    pypi
scikit-learn              0.24.2           py38h26428f7_1    conda-forge
scipy                     1.7.0            py38hd0c9ec0_0    conda-forge
send2trash                1.7.1                    pypi_0    pypi
setuptools                49.6.0           py38h10201cd_3    conda-forge
six                       1.16.0                   pypi_0    pypi
sleef                     3.5.1                h27ca646_1    conda-forge
sqlite                    3.36.0               h72a2b83_0    conda-forge
terminado                 0.10.1                   pypi_0    pypi
testpath                  0.5.0                    pypi_0    pypi
threadpoolctl             2.2.0              pyh8a188c0_0    conda-forge
tk                        8.6.10               hf7e6567_1    conda-forge
torchtext                 0.10.0                   pypi_0    pypi
torchvision               0.9.0           py38h4ddca67_0_cpu    conda-forge
tornado                   6.1                      pypi_0    pypi
tqdm                      4.61.2                   pypi_0    pypi
traitlets                 5.0.5                    pypi_0    pypi
typing_extensions         3.10.0.0           pyha770c72_0    conda-forge
urllib3                   1.26.6                   pypi_0    pypi
wcwidth                   0.2.5                    pypi_0    pypi
webencodings              0.5.1                    pypi_0    pypi
wheel                     0.36.2             pyhd3deb0d_0    conda-forge
widgetsnbextension        3.5.1                    pypi_0    pypi
xz                        5.2.5                h642e427_1    conda-forge
zlib                      1.2.11            h31e879b_1009    conda-forge
zstd                      1.5.0                h861e0a7_0    conda-forge

and python version is

(CV)  san  ~/work/python
 python --version
Python 3.8.6

So what I see is

(CV)  san  ~/work/python
 pip install mediapipe
ERROR: Could not find a version that satisfies the requirement mediapipe (from versions: none)
ERROR: No matching distribution found for mediapipe

So, I've try to solve this for several weeks but many ppl gave us(who suffer on this problem like me) like

1.downgrading python version

2.downgrading bazel to 3.7.2 from 4.x

but python version is not really matter on mediapipe and I'm not sure but mediapipe on bazel is for C++ or something but anyway there is no way to downgrade it. (you can see it on here)

any solution????

Roseroseann answered 5/8, 2021 at 2:18 Comment(1)
O
9

IMPORTANT EDIT: Please refer to other answers. The solution I provide was a workaround and is no longer needed (MediaPipe is now supported on silicon chips).


The following answer is courtesy of user josiahsrc on GitHub.

Here are the steps you need to take in order to use mediapipe with Apple's M1:

  1. 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.
  2. Open a new Terminal window. (If terminal was previously opened, quit and relaunch it).
  3. 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.
  4. 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 [email protected]. This installation may take a while.
  5. 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/[email protected]/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/[email protected]/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.
  6. 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.
  7. Now you should be inside the Virtual Environment, upgrade pip. pip install --upgrade pip
  8. 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/[email protected]/bin/python3). Now you should be able to use mediapipe.

Oden answered 29/9, 2021 at 22:44 Comment(5)
But that's an x86_64 install of mediapipe that you're running through an emulator, not a native ARM mediapipe? What's the performance penalty of running the emulated version?Spiritoso
Not through an emulator, the installation is translated by a translation layer in a separate environment (The virtual environment). An emulator would suggest that you'd be only able to use what you installed on the emulator. Which is not the case here. After the installation above you can open the project on PyCharm as you'd usually do. You just have to use the x86_64 version of python (which your machine can run in terminal also).Oden
can you use this with miniforge?Lourdeslourie
Yes, I can't see why you wouldn't be able toOden
@Oden how do you adapt this to run in Miniforge? I have TensorFlow only working in a Miniforge env and would like to get mediapipe in the same env. Thank you.Driest
X
8
pip install mediapipe-silicon

see here for more info

Also look at the readme at https://github.com/cansik/mediapipe-silicon

You might need to downgrade protobuf to 3.20.1 or lower.

Running

pip uninstall protobuf
pip install protobuf==3.20.1

... worked for me.

Xiomaraxiong answered 24/5, 2022 at 14:7 Comment(0)
S
3

I was also facing the same problem but this worked for me and also this is the best and also a safe way to download mediapipe on Mac m1.

pip install mediapipe-silicon
Splanchnology answered 4/6, 2022 at 7:46 Comment(0)
W
1

If you don't mind setting the arch every time, this will work too.

$ arch -x86_64 pip install mediapipe
$ arch -x86_64 python
>>> import mediapipe as mp

Edit: At the time of this answer, PyPi only has packages for Python3.8 for MacOS, so make sure you have a virtual environment of the same.

Woeful answered 20/1, 2022 at 6:14 Comment(0)
L
1

I was having an issue installing mediapipe on a Mac m1 and this worked for me

pip install mediapipe-silicon
Lifeguard answered 28/7, 2022 at 19:34 Comment(0)
L
0

The best way is build mediapipe from source:

1- install dependencies:

brew install bazelisk
brew install opencv@3
# There is a known issue caused by the glog dependency. Uninstall glog.
brew uninstall --ignore-dependencies glog
pip3 install --user six

2- Checkout MediaPipe repository:

git clone https://github.com/google/mediapipe.git
cd mediapipe

3- build:

python3.9 setup.py install
Linage answered 8/6, 2022 at 17:50 Comment(0)
T
-1

I am using Macbook Air M1 2020 and this worked for me perfectly

$ arch -x86_64 pip install mediapipe

Turfman answered 27/2, 2022 at 11:43 Comment(1)
Are you sure? The M1 is not running on a x86_64 architecture but on arm64 so that shouldn't work.Unsteady

© 2022 - 2024 — McMap. All rights reserved.