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 (?).
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. ..
$ 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