# RuntimeError: Unable to locate turbojpeg library automatically

**URL:** <https://discourse.farm-ng.com/t/runtimeerror-unable-to-locate-turbojpeg-library-automatically/57>\
**Category:** support\
**Created:** [February 14, 2023, 8:24pm UTC](https://discourse.farm-ng.com/t/runtimeerror-unable-to-locate-turbojpeg-library-automatically/57 "2023-02-14T20:24:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kylecoble](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.farm-ng.com/kylecoble/32/12_2.png) [@kylecoble](https://discourse.farm-ng.com/u/kylecoble)\
**Post date:** [February 14, 2023, 8:24pm UTC](https://discourse.farm-ng.com/t/runtimeerror-unable-to-locate-turbojpeg-library-automatically/57/1 "2023-02-14T20:24:35Z")

</div>

### What package and version are you using?

- `farm-ng-amiga` version `v0.0.5`
- `camera-streamer` `v0.0.1` (commit: [Command line args (#5) · farm-ng/camera-streamer-kivy@67c65f8 · GitHub](https://github.com/farm-ng/camera-streamer/commit/67c65f82ebf03830f2d90bd268ba12418733573e))
- `virtual-joystick` `v0.0.2` (commit: [Build joystick.kv in VirtualJoystickWidget (#4) · farm-ng/virtual-joystick@a05a17d · GitHub](https://github.com/farm-ng/virtual-joystick/commit/a05a17dcbfd83bc01d17c64b1f4555dd0a270085))

### Please, describe the issues you are seeing?

**Important note: this is not an issue when running the apps on the Amiga or on a Linux computer.  
This is only relevant if you choose to develop by running the apps locally on a Windows or Mac computer.**

When running the [`camera-streamer`](https://github.com/farm-ng/camera-streamer) or [`virtual-joystick`](https://github.com/farm-ng/virtual-joystick) examples locally on a Windows (using WSL) or Mac computer, you may see an error:

```auto
 Traceback (most recent call last):
...
 RuntimeError: Unable to locate turbojpeg library automatically. You may specify the turbojpeg library path manually.
WARNING:kivy:stderr: RuntimeError: Unable to locate turbojpeg library automatically. You may specify the turbojpeg library path manually.
 e.g. jpeg = TurboJPEG(lib_path)
WARNING:kivy:stderr: e.g. jpeg = TurboJPEG(lib_path)

```

- **See bottom of post for full Traceback**

It seems that the auto-discovery of the install path for `pip install PyTurboJPEG` is not reliable on a WSL or Mac OS. You have two options:

### 1. Follow instructions for alternative install methods for your local machine, detailed in their github readme and in the following issue:

> <https://github.com/lilohuang/PyTurboJPEG/issues/27>
>
> I \`pip3 install PyTurboJPEG\`. When I run an open-source \`openpose\` code, I encou…nter this issue. Anyone facing this similar issue?

This is resolved on WSL with:

```auto
sudo apt-get update -y
sudo apt-get install -y libturbojpeg

```

This is resolved on Mac with:

```auto
brew install jpeg-turbo

```

This is the preferred approach (see below), but does require a system level install which you may want to avoid (it’s usually nice to minimize system level installs).

### 2. Switch to opencv image decoding.

The advantage here is that the `pip install opencv-python` works for all OS, but the downside is that the image decoding is 1.5 -2x slower than PyTurboJpeg (see below).

You can see how this is done in this example pull request: [Demonstrate OpenCV image decoding (remove PyTurboJpeg dependency) by Hackerman342 · Pull Request #7 · farm-ng/camera-streamer-kivy · GitHub](https://github.com/farm-ng/camera-streamer/pull/7/files)

The key line in Python is:

```auto
img = cv2.imdecode(
    np.frombuffer(getattr(frame, view_name).image_data, dtype=np.uint8),
    cv2.IMREAD_UNCHANGED,
)

```

### For reference

#### Decoding speed comparison

I compared the decoding time (only the 1-2 lines for decoding, nothing else) using opencv & numpy to PyTurboJpeg on the brain. What I saw was:

> - RGB:
> - Shape: (1080, 1920, 3)
> - PyTurboJpeg: 28.5 ms
> - OpenCV: 46.0 ms
> 
> - greyscale):
> - Shape: (400, 640, 3
> - PyTurboJpeg: 4.1 ms
> - OpenCV: 5.8 ms

* * *

This shows there’s a notable benefit to using PyTurboJpeg for decoding, especially for RGB images.

#### Full Traceback:

```auto
 Traceback (most recent call last):
WARNING:kivy:stderr: Traceback (most recent call last):
   File "/home/kcoble/camera-streamer/src/main.py", line 156, in <module>
WARNING:kivy:stderr: File "/home/kcoble/camera-streamer/src/main.py", line 156, in <module>
     CameraApp(args.address, args.port, args.stream_every_n).app_func()
WARNING:kivy:stderr: CameraApp(args.address, args.port, args.stream_every_n).app_func()
   File "/home/kcoble/camera-streamer/src/main.py", line 50, in __init__
WARNING:kivy:stderr: File "/home/kcoble/camera-streamer/src/main.py", line 50, in __init__
     self.image_decoder = TurboJPEG()
WARNING:kivy:stderr: self.image_decoder = TurboJPEG()
   File "/home/kcoble/camera-streamer/venv/lib/python3.8/site-packages/turbojpeg.py", line 298, in __init__
WARNING:kivy:stderr: File "/home/kcoble/camera-streamer/venv/lib/python3.8/site-packages/turbojpeg.py", line 298, in __init__
     self.__find_turbojpeg() if lib_path is None else lib_path)
WARNING:kivy:stderr: self.__find_turbojpeg() if lib_path is None else lib_path)
   File "/home/kcoble/camera-streamer/venv/lib/python3.8/site-packages/turbojpeg.py", line 926, in __find_turbojpeg
WARNING:kivy:stderr: File "/home/kcoble/camera-streamer/venv/lib/python3.8/site-packages/turbojpeg.py", line 926, in __find_turbojpeg
     raise RuntimeError(
WARNING:kivy:stderr: raise RuntimeError(
 RuntimeError: Unable to locate turbojpeg library automatically. You may specify the turbojpeg library path manually.
WARNING:kivy:stderr: RuntimeError: Unable to locate turbojpeg library automatically. You may specify the turbojpeg library path manually.
 e.g. jpeg = TurboJPEG(lib_path)
WARNING:kivy:stderr: e.g. jpeg = TurboJPEG(lib_path)

```
