# Opencv-python and opencv-python-headless

**URL:** <https://community.ultralytics.com/t/opencv-python-and-opencv-python-headless/1022>\
**Category:** Support\
**Tags:** question\
**Created:** [April 29, 2025, 9:03am UTC](https://community.ultralytics.com/t/opencv-python-and-opencv-python-headless/1022 "2025-04-29T09:03:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![quent](https://avatars.discourse-cdn.com/v4/letter/q/e19adc/32.png) [@quent](https://community.ultralytics.com/u/quent)\
**Post date:** [April 29, 2025, 9:03am UTC](https://community.ultralytics.com/t/opencv-python-and-opencv-python-headless/1022/1 "2025-04-29T09:03:50Z")

</div>

Hello everybody, wanted to know if ulltralytics team would finally build a package of their tool using opencv-python-headless and not opencv-python ? With the regular opencv version, libGL is required (openGL support), which is not really necessary in some project when doing inference only (no need for visuals created with opencv highgui lib). There are tricks to avoid that issue (like removing regular opencv and reinstalling the headless version) but it’s not so clean.  
Thanks!

---

<div class="post-metadata">

**Author:** ![BurhanQ](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/burhanq/32/7_2.png) [@BurhanQ](https://community.ultralytics.com/u/BurhanQ)\
**Post date:** [April 29, 2025, 11:37am UTC](https://community.ultralytics.com/t/opencv-python-and-opencv-python-headless/1022/2 "2025-04-29T11:37:56Z")

</div>

There have been a few Pull Requests opened for this exact request

- [Build with `opencv-python` in headless version by Pandede · Pull Request #7068 · ultralytics/ultralytics · GitHub](https://github.com/ultralytics/ultralytics/pull/7068)
- [refactor: split out base dependencies to reduce docker image size by antoniomdk · Pull Request #17527 · ultralytics/ultralytics · GitHub](https://github.com/ultralytics/ultralytics/pull/17527)

and a recent issue (with several others):

- [opencv-python-headless install mechanism · Issue #20385 · ultralytics/ultralytics · GitHub](https://github.com/ultralytics/ultralytics/issues/20385)

From what I’m aware of, there are complications in using the `headless` install of OpenCV for Python WRT existing code and user workflows. It’s always a difficult to decide which features to integrate vs leave out, especially when they’re requested frequently. It’s entirely plausible that it could be added, but there would need to be a bit of effort put in to ensure that the default install would work as expected, and that a `headless` option would be secondary.

I think for anyone building a Docker image for running a container, your suggestion about removing regular OpenCV and installing the headless version instead, might be a valid step, but `libGL` would probably get installed/updated anyhow to get the base install working. I suspect that for many in this situation, cloning the repo, modifying the `pyproject.toml`, updating the Dockerfile, and then building the Docker image would be the quickest way to create a `headless` version.

If not using Docker, then modifying the `pyproject.toml` in a local clone of Ultralytics and building the project should provide an installable of a `headless` version. The effort for either is relatively low, and if it breaks existing workflows for training or validation, it might not matter for the individual where it would impact many more users if integrated directly into Ultralytics.

---

<div class="post-metadata">

**Author:** ![quent](https://avatars.discourse-cdn.com/v4/letter/q/e19adc/32.png) [@quent](https://community.ultralytics.com/u/quent)\
**Post date:** [April 30, 2025, 1:36pm UTC](https://community.ultralytics.com/t/opencv-python-and-opencv-python-headless/1022/3 "2025-04-30T13:36:57Z")

</div>

Many thanks for your answer! We appreciate your reactivity! I understand your point of view. For information, libGL is not necessary if opencv-python-headless is used. And that was what i wanted: don’t install libGL on my linux image. Another way is to infer with another lib that ultralytics: thanks to your export functions, it is possible to work with openvino or onnx. And with that way i can work without libGL installed. Now i’ve got another question related to that: i wanted to use pure pytorch tools for inference but when loading my model (.pt file) there are always artifacts from ultralytics remaining in the serialized file. Isn’t it possible to make an export structure which is 100% pytorch compatible ?

---

<div class="post-metadata">

**Author:** ![Toxite](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/toxite/32/123_2.png) [@Toxite](https://community.ultralytics.com/u/Toxite)\
**Post date:** [May 1, 2025, 9:18am UTC](https://community.ultralytics.com/t/opencv-python-and-opencv-python-headless/1022/4 "2025-05-01T09:18:51Z")

</div>

There isn’t such a thing as pure PyTorch. All custom modules have definition. And loading `.pt` file requires those definition to be present. This is true for any model, not just the ones in Ultralytics and it is simply how `.pt` (or pickle to be precise) files work. You can’t decouple them from the module definitions. Best you can do is use a format like TorchScript.

---

<div class="post-metadata">

**Author:** ![BurhanQ](https://sea1.discourse-cdn.com/flex001/user_avatar/community.ultralytics.com/burhanq/32/7_2.png) [@BurhanQ](https://community.ultralytics.com/u/BurhanQ)\
**Post date:** [May 1, 2025, 1:28pm UTC](https://community.ultralytics.com/t/opencv-python-and-opencv-python-headless/1022/5 "2025-05-01T13:28:15Z")

</div>

I suspect the easiest and quickest way to get a build without `libGL` would be to clone the repo, modify the `pyproject.toml` dependencies to use `opencv-python-headless`, update the [Dockerfile](https://github.com/ultralytics/ultralytics/blob/e1d742500fbfc24a08c4eb664d0111eaffc8827a/docker/Dockerfile) to avoid the `libGL` install, and then build the container.
