Last updated: Apr 10, 2024
Reading timeยท3 min
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.
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'
If you are on Ubuntu, install the prerequisites as shown in the error message.
sudo apt install libgtk2.0-dev pkg-config
opencv-python-headless
moduleMake sure you don't have the opencv-python-headless
module installed because
it causes conflicts with opencv-python.
# ๐๏ธ 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
opencv-python
moduleNow, uninstall the opencv-python
module as well.
# ๐๏ธ 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.
# ๐๏ธ 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.
pip freeze > requirements.txt
If you got the error in Spyder IDE, try restarting it.
opencv-python
packageIf the error persists, try to run the installation command with the --upgrade
option.
pip install opencv-python --upgrade pip3 install opencv-python --upgrade python -m pip install opencv-python --upgrade python3 -m pip install opencv-python --upgrade
The --upgrade option upgrades the specified package to the newest available version.
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.
pip install
command with the virtual environment active.# ๐๏ธ 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
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.
pip freeze > requirements.txt
You can learn more about the related topics by checking out the following tutorials: