mediapipe/docs/getting_started/python.md
MediaPipe Team 2b58cceec9 Project import generated by Copybara.
GitOrigin-RevId: d8caa66de45839696f5bd0786ad3bfbcb9cff632
2020-12-09 22:43:33 -05:00

3.3 KiB

layout title parent has_children has_toc nav_order
default MediaPipe in Python Getting Started true false 3

MediaPipe in Python

{: .no_toc }

  1. TOC {:toc}

Ready-to-use Python Solutions

MediaPipe offers ready-to-use yet customizable Python solutions as a prebuilt Python package. MediaPipe Python package is available on PyPI for Linux, macOS and Windows.

You can, for instance, activate a Python virtual environment:

$ python3 -m venv mp_env && source mp_env/bin/activate

Install MediaPipe Python package and start Python intepreter:

(mp_env)$ pip install mediapipe
(mp_env)$ python3

In Python interpreter, import the package and start using one of the solutions:

import mediapipe as mp
mp_face_mesh = mp.solutions.face_mesh

Tip: Use command deactivate to later exit the Python virtual environment.

To learn more about configuration options and usage examples, please find details in each solution via the links below:

MediaPipe on Google Colab

MediaPipe Python Framework

The ready-to-use solutions are built upon the MediaPipe Python framework, which can be used by advanced users to run their own MediaPipe graphs in Python. Please see here for more info.

Building MediaPipe Python Package

Follow the steps below only if you have local changes and need to build the Python package from source. Otherwise, we strongly encourage our users to simply run pip install mediapipe to use the ready-to-use solutions, more convenient and much faster.

  1. Make sure that Bazel and OpenCV are correctly installed and configured for MediaPipe. Please see Installation for how to setup Bazel and OpenCV for MediaPipe on Linux and macOS.

  2. Install the following dependencies.

    Debian or Ubuntu:

    $ sudo apt install python3-dev
    $ sudo apt install python3-venv
    $ sudo apt install -y protobuf-compiler
    

    macOS:

    $ brew install protobuf
    

    Windows:

    Download the latest protoc win64 zip from the Protobuf GitHub repo, unzip the file, and copy the protoc.exe executable to a preferred location. Please ensure that location is added into the Path environment variable.

  3. Activate a Python virtual environment.

    $ python3 -m venv mp_env && source mp_env/bin/activate
    
  4. In the virtual environment, go to the MediaPipe repo directory.

  5. Install the required Python packages.

    (mp_env)mediapipe$ pip3 install -r requirements.txt
    
  6. Generate and install MediaPipe package.

    (mp_env)mediapipe$ python3 setup.py gen_protos
    (mp_env)mediapipe$ python3 setup.py install --link-opencv