Through the installation of pip package that depends on opencv-python when building opencv from source code

Overview

I built opencv from source code in this article. I can do ʻimport cv2` from my own program, but when I try to install a package that depends on opencv-python, I get angry because there is no opencv-python. Since I just put a symbolic link on site-packages, does it mean that opencv is included in pip? By the way, it seems that cmake did not specify the location of pip.

So, I made a package that wraps cv2. ʻImport cv2` can be done, so I thought it might be possible to make an empty opencv-python package and cheat, but since it was a big deal, I wrapped it properly (?).

Constitution

The configuration is as follows.

wheel/
├── build               #The build is output
├── cv2                 #Become a package name
│   ├── __init__.py     #Show it as cv2 outside
│   └── _native
│       ├── cv2.cpython-36m-aarch64-linux-gnu.so #entity
│       └── __init__.py #Import the original cv2
├── dist                #The whl file is output. Pip install this
├── MANIFEST.in         #Specify the entity.
└── setup.py            #Various settings of pip

The contents of each file are as follows. __init__.py I don't know anything. ..

setup.py


from setuptools import setup
from setuptools.dist import Distribution

class BinaryDistribution(Distribution):
    def has_ext_modules(foo):
        return True

long_description = "long description of the wheel"

setup(
    name='opencv-python',
    packages=['cv2'],
    version='3.4.3',

    include_package_data=True,
    distclass=BinaryDistribution,

    author='devmikyom',
    description='OpenCV wrapper for Ubuntu 20.04 on raspberry pi 4',
    long_description = long_description,
    classifiers=[
        'Programming Language :: Python :: 3.6'
    ]
)

:MANIFEST:in


include cv2/_native/cv2.cpython-36m-aarch64-linux-gnu.so

wheel/cv2/__init__.py


from ._native.cv2 import *
__version__ = '3.4.3'

wheel/cv2/_native/__init__.py


from .cv2 import *

__init__.py I really don't know anything. ..

Build and install

$ python setup.py bdist_wheel
$ pip install dist/opencv_python-3.4.3-cp36-cp36m-linux_aarch64.whl

ʻImport cv2` It seems that it can be seen as pip and opencv-python. I'm not sure if this really suits me ...

Recommended Posts

Through the installation of pip package that depends on opencv-python when building opencv from source code
Get only the source code of the PyPI package with pip from the command line
Source code of "Set the color on the poster side so that the color of Youtube subtitles changes automatically."
Easy installation of OpenCV on RaspberryPi 3+
"Cython" tutorial to make Python explosive: When C ++ code depends on the library. First of all, CMake.
Installation method using the pip command of the Python package (library) Mac environment
Install the latest version of Apache httpd 2.4 from source on Cent OS 8
The case that the installation of pip became easier before I knew it
How to solve the problem that only the process remains when you press cross on the imshow screen of OpenCV
Install PostgreSQL from source code on CentOS
Error details and countermeasures that occurred in OpenCv2 when executing the object recognition sample program of "Object Detect on Tools"