Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 340
Bill Avatar asked Mar 08 '17 17:03

Bill


1 Answers

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)

like image 99
Tomasz Gandor Avatar answered Nov 01 '22 06:11

Tomasz Gandor