10

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.

Bill
  • 698
  • 1
  • 5
  • 22
  • Are you able to `import numpy`? Their website states that `numpy` is required. Another option might be to try this unofficial port: https://pypi.python.org/pypi/opencv-python – pekapa Mar 11 '17 at 13:16
  • Yeah, normally I have no issues using `numpy` or `cv2`. But trying to create a package that uses `cv2` is causing an issue (see edit in post). I considered using the unofficial port, but I want to be sure that what I add in the future will be in line with OpenCV standards (and that I'll have clear docs for new functions). – Bill Mar 13 '17 at 18:34
  • 1
    Oh, so that's the problem. `cv2` is not a package that can be installed. If you copy/pasted the `cv2.pyd` file to your project, I don't think you need to put it under `install_requires`, just make sure that file is delivered with your package or that the users can add that file themselves. – pekapa Mar 13 '17 at 19:51
  • I was afraid that might be the case. – Bill Mar 14 '17 at 16:03

2 Answers2

13

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)

James Adams
  • 8,448
  • 21
  • 89
  • 148
Tomasz Gandor
  • 8,235
  • 2
  • 60
  • 55
  • 2
    What if it has to be the official opencv? What should be put there? Perhaps in this case it's left out and just specified as a sort of requirement in the README? – CMCDragonkai Mar 22 '18 at 00:14
  • @CMCDragonkai have you found a solution? I believe python has no way of specifying such requirements :( – Ciprian Tomoiagă Oct 15 '18 at 14:14
  • unfortunately Pycharm (2018.2) still complains about cv2 if opencv-python-headless is specified in the requirements – Glen Dec 02 '20 at 17:43
1

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"

Shirantha Madusanka
  • 1,461
  • 1
  • 11
  • 16