2

I'm trying to collect python code in a package gnn_pylib and install it in my conda environment. My package will require opencv, which has been installed in my conda environment via:

conda install -c conda-forge opencv

I can run cv2 functions correctly, and I can call functions in the packages using cv2 functions successfully:

import gnn_pylib
gnn_pylib.show()

But when i try to install the package running pip install -e . from the gnn_pylib directory I get the following error:

Collecting cv2 (from gnn-pylib==0.1)
  Could not find a version that satisfies the requirement cv2 (from gnn-pylib==0.1) (from versions: )
No matching distribution found for cv2 (from gnn-pylib==0.1)

Is there something i am missing? should I some way inform pip but my conda opencv?

The package has the following structure:

gnn_pylib/
    gnn_pylib/
        __init__.py
        show.py
    setup.py

__init__.py is as follows:

from .show import foo

show.py is as follows:

import cv2
import numpy as np

def foo():
    cv2.imshow("random", np.random.rand(10,10))
    cv2.waitKey()
    return

setup.py is as follows:

from setuptools import setup

setup(name='gnn_pylib',
      version='0.1',
      description='General purpose python library',
      url='http://github.com/whatever/gnn_pylib',
      author='whatever',
      author_email='whatever@gmail.com',
      license='MIT',
      packages=['gnn_pylib'],
      install_requires=[
            'numpy',
            'cv2',
      ],
      zip_safe=False)
Gianni
  • 458
  • 5
  • 17

2 Answers2

3

Rather than using cv2 as the required package name instead use opencv-python since that's the name of the OpenCV bindings package available from PyPI. So your setup.py file will instead look like this (same as above with different entry for the OpenCV bindings package requirement):

from setuptools import setup

setup(name='gnn_pylib',
      version='0.1',
      description='General purpose python library',
      url='http://github.com/whatever/gnn_pylib',
      author='whatever',
      author_email='whatever@gmail.com',
      license='MIT',
      packages=['gnn_pylib'],
      install_requires=[
            'numpy',
            'opencv-python',
      ],
      zip_safe=False)
James Adams
  • 8,448
  • 21
  • 89
  • 148
0

@James Adams answer the specific case for cv2, replacing with more compatible opencv-python.

However, if you still want to have dependencies install from conda, consider make a conda package.

See similar question with answer:

setup.py with dependecies installed by conda (not pip)

Use 'conda install' instead of 'pip install' for setup.py packages

I cannot find answer with detail step-by-step and example yet. But hope it help.

Haha TTpro
  • 5,137
  • 6
  • 45
  • 71