OpenCV error: The function is not implemented [Solved]

avatar
Borislav Hadzhiev

Last updated: Apr 10, 2024
3 min

banner

# OpenCV error: The function is not implemented [Solved]

The OpenCV "error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support" occurs because of having missing dependencies or opencv-python-headless installed.

To solve the error, uninstall opencv-python-headless and install all missing dependencies.

shell
OpenCV(4.5.1) C:\Users\bobbyhadz\AppData\Local\Temp\opencv\modules\src\window.cpp:451: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'

# Install the prerequisites on Ubuntu

If you are on Ubuntu, install the prerequisites as shown in the error message.

shell
sudo apt install libgtk2.0-dev pkg-config

install prerequisites on ubuntu

# Uninstall the opencv-python-headless module

Make sure you don't have the opencv-python-headless module installed because it causes conflicts with opencv-python.

shell
# ๐Ÿ‘‡๏ธ Uninstall the package that caused the conflict pip uninstall opencv-python-headless pip3 uninstall opencv-python-headless python -m pip uninstall opencv-python-headless python3 -m pip uninstall opencv-python-headless

uninstall opencv python headless

# Reinstall the opencv-python module

Now, uninstall the opencv-python module as well.

shell
# ๐Ÿ‘‡๏ธ Uninstall opencv-python pip uninstall opencv-python pip3 uninstall opencv-python python -m pip uninstall opencv-python python3 -m pip uninstall opencv-python

Finally, reinstall opencv-python.

shell
# ๐Ÿ‘‡๏ธ install opencv-python pip install opencv-python pip3 install opencv-python python -m pip install opencv-python python3 -m pip install opencv-python

If the error is resolved after reinstalling opencv-python, update your requirements.txt file with the following command.

shell
pip freeze > requirements.txt

If you got the error in Spyder IDE, try restarting it.

# Update your version of the opencv-python package

If the error persists, try to run the installation command with the --upgrade option.

shell
pip install opencv-python --upgrade pip3 install opencv-python --upgrade python -m pip install opencv-python --upgrade python3 -m pip install opencv-python --upgrade

upgrade opencv package

The --upgrade option upgrades the specified package to the newest available version.

# Create a virtual environment

If none of the suggestions helped, try creating a virtual environment as you might have clashing versions of the opencv-python, opencv-python-headless and opencv-contrib-python packages installed.

  1. Create a virtual environment.
  2. Activate the virtual environment.
  3. Run the pip install command with the virtual environment active.
shell
# ๐Ÿ‘‡๏ธ Use the correct version of Python when creating VENV python -m venv venv # ๐Ÿ‘‡๏ธ Activate on Unix or MacOS source venv/bin/activate # ๐Ÿ‘‡๏ธ Activate on Windows (cmd.exe) venv\Scripts\activate.bat # ๐Ÿ‘‡๏ธ Activate on Windows (PowerShell) venv\Scripts\Activate.ps1 # ๐Ÿ‘‡๏ธ Install the specific package in the virtual environment pip install opencv-python

If the python -m venv venv command doesn't work, try the following 2 commands:

  • python3 -m venv venv
  • py -m venv venv
Make sure to use the correct command to activate your virtual environment depending on your operating system and your shell.

Your virtual environment will use the version of Python that was used to create it.

If the error is resolved after installing opencv-python in a virtual environment, update your requirements.txt file with the following command.

shell
pip freeze > requirements.txt

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2024 Borislav Hadzhiev