Installation

Install Python

LayoutParser is a Python package that requires Python >= 3.6. If you do not have Python installed on your computer, you might want to turn tothe official instruction to download and install the appropriate version of Python.

Install the LayoutParser library

After several major updates, LayoutParser provides various functionalities and deep learning models from different backends. However, you might only need a fraction of the functions, and it would be redundant for you to install all the dependencies when they are not required. Therefore, we design highly customizable ways for installing the LayoutParser library:

CommandDescription
pip install layoutparserInstall the base LayoutParser Library
It will support all key functions in LayoutParser, including:
1. Layout Data Structure and operations
2. Layout Visualization
3. Load/export the layout data
pip install "layoutparser[effdet]"Install LayoutParser with Layout Detection Model Support
It will install the LayoutParser base library as well as
supporting dependencies for theEfficientDet-based layout detection models.
pip install layoutparser torchvision && pip install "git+https://github.com/facebookresearch/detectron2.git@v0.5#egg=detectron2"Install LayoutParser with Layout Detection Model Support
It will install the LayoutParser base library as well as
supporting dependencies for theDetectron2-based layout detection models. See details inAdditional Instruction: Install Detectron2 Layout Model Backend.
pip install "layoutparser[paddledetection]"Install LayoutParser with Layout Detection Model Support
It will install the LayoutParser base library as well as
supporting dependencies for thePaddleDetection-based layout detection models.
pip install "layoutparser[ocr]"Install LayoutParser with OCR Support
It will install the LayoutParser base library as well as
supporting dependencies for performing OCRs. See details inAdditional Instruction: Install OCR utils.

Additional Instruction: Install Detectron2 Layout Model Backend

For Mac OS and Linux Users

If you would like to use the Detectron2 models for layout detection, you might need to run the following command:

pip install layoutparser torchvision&& pip install"detectron2@git+https://github.com/facebookresearch/detectron2.git@v0.5#egg=detectron2"

This might take some time as the command willcompile the library. If you also want to install a Detectron2 versionwith GPU support or encounter some issues during the installation process, please refer to the official Detectron2installation instruction for detailedinformation.

For Windows users

As reported by many users, the installation of Detectron2 can be rather tricky on Windows platforms. In our extensive tests, we find that it is nearly impossible to provide a one-line installation command for Windows users. As a workaround solution, for now we list the possible challenges for installing Detectron2 on Windows, and attach helpful resources for solving them. We are also investigating other possibilities to avoid installing Detectron2 to use pre-trained models. If you have any suggestions or ideas, please feel free tosubmit an issue in our repo.

  1. Challenges for installingpycocotools

    • You can find detailed instructions onthis post from Chang Hsin Lee.

    • Another solution is try to installpycocotools-windows, see https://github.com/cocodataset/cocoapi/issues/415.

  2. Challenges for installingDetectron2

    • @ivanpp curates a detailed description for installingDetectron2 on Windows:Detectron2 walkthrough (Windows)

    • Detectron2 maintainers claim that they won’t provide official support for Windows (see1 and2), but Detectron2 is continuously built on windows with CircleCI (see3). Hopefully this situation will be improved in the future.

Additional Instructions: Install OCR utils

Layout Parser also comes with supports for OCR functions. In order to use them, you need to install the OCR utils via:

pip install"layoutparser[ocr]"

Additionally, if you want to use the Tesseract-OCR engine, you also need to install it on your computer. Please check theofficial documentation for detailed installation instructions.

Known issues

Error: instantiating `lp.GCVAgent.with_credential` returns module 'google.cloud.vision' has no attribute 'types'.

In this case, you have a newer version of the google-cloud-vision. Please consider downgrading the API using:

pip install -U layoutparser[ocr]