Bill
Bill

Reputation: 798

How do I add cv2 as a requirement in a python package?

I'm trying to make my own package which uses OpenCV Python module cv2. However when using PyCharm, it warns that the

Package requirement is not satisfied.

I suspect this is because I used the recommended method of copy/pasting cv2.pyd into my python dir. Note that pip install cv2 doesn't work.

What's the right method to ensure that requirements are met when this package is brought in?

EDIT:

My setup.py file is as follows

from setuptools import setup

setup(name='image_processing',
      version='0.1',
      install_requires=['numpy', 'scipy', 'cv2'],
      description='Collection of useful image processing functions',
      url='',
      author='Bill',
      license='MIT',
      packages=['image_processing'],
      zip_safe=False)

This is where the error shows up when trying to package my code. Normally I have no issues importing numpy or cv2. I installed Numpy using pip, and cv2 via the method mentioned above. Everything works if I just run scripts using cv2, but it's this packaging that's tricking me up.

Upvotes: 10

Views: 19998

Answers (2)

Tomasz Gandor
Tomasz Gandor

Reputation: 8833

You need to add opencv-python to requirements.

The package is here: https://pypi.python.org/pypi/opencv-python

Then, your requirements.txt file is OK, but sometimes PyCharm keeps whining. If this is the case, then next to the "Install requirement" label there is "Ignore requirement". The latter is your way to go.

(current - 2018.2 PyCharm version does not complain about cv2 when opencv-python is specified in requirements)

Upvotes: 13

Shirantha Madusanka
Shirantha Madusanka

Reputation: 1695

You have to specify the version of the opencv python package. "pip install opencv-python==2.4.9"

Find the proper version from here.

If you want to install latest opencv python package, use "pip install opencv-python"

Upvotes: 1

Related Questions