Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 703658 - media-libs/opencv Unable to import cv2 with python after emerging opencv
Summary: media-libs/opencv Unable to import cv2 with python after emerging opencv
Status: UNCONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Amy Liffey
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-12-24 14:21 UTC by Hendrik Klug
Modified: 2020-05-21 19:05 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
build log of emerge media-libs/opencv (emerge_media-libs_opencv_log.txt.xz,22.78 KB, application/x-xz)
2019-12-25 18:27 UTC, Hendrik Klug
Details
opencv-4.1.2-python-lib-suffix-hack.patch (opencv-4.1.2-r2.patch,628 bytes, patch)
2019-12-30 15:39 UTC, Zitian Li
Details | Diff
ebuild patch to re-enable the python modules (opencv-4.1.2-r2.ebuild.patch,850 bytes, patch)
2020-01-23 00:44 UTC, Tiago Resende
Details | Diff
Fix for opencv-3.4.1-r7 to build with python bindings (file_703658.txt,552 bytes, patch)
2020-03-09 01:01 UTC, Judge Dredd
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Hendrik Klug 2019-12-24 14:21:22 UTC
I am unable to import cv2 with python, emerging opencv does not seem to install any python modules.

`
[I] media-libs/opencv
     Available versions:  2.4.13-r3(0/2.4) 3.4.1-r7(0/3.4.1) (~)4.1.2-r1(0/4.1.2) (~)4.1.2-r2(0/4.1.2) {contrib contribcvv contribdnn contribhdf contribsfm contribxfeatures2d cuda debug dnnsamples -download +eigen examples +features2d ffmpeg gdal gflags glog gphoto2 gstreamer gtk ieee1394 java jpeg jpeg2k lapack libav opencl opencvapps openexr opengl openmp pch png +python qt5 tesseract testprograms threads tiff v4l vaapi vtk webp xine ABI_MIPS="n32 n64 o32" ABI_RISCV="lp64 lp64d" ABI_S390="32 64" ABI_X86="32 64 x32" CPU_FLAGS_X86="avx avx2 fma3 popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3" ELIBC="FreeBSD" PYTHON_SINGLE_TARGET="+python2_7" PYTHON_TARGETS="(+)python2_7 python3_5 python3_6 python3_7"}
     Installed versions:  4.1.2-r2(0/4.1.2)(17:24:33 23/12/19)(eigen features2d gstreamer gtk jpeg opengl openmp png python tiff -contrib -contribcvv -contribdnn -contribhdf -contribsfm -contribxfeatures2d -cuda -debug -dnnsamples -download -examples -ffmpeg -gdal -gflags -glog -gphoto2 -ieee1394 -java -jpeg2k -lapack -libav -opencl -opencvapps -openexr -pch -qt5 -tesseract -testprograms -threads -v4l -vaapi -vtk -webp -xine ABI_MIPS="-n32 -n64 -o32" ABI_RISCV="-lp64 -lp64d" ABI_S390="-32 -64" ABI_X86="64 -32 -x32" CPU_FLAGS_X86="sse sse2 -avx -avx2 -fma3 -popcnt -sse3 -sse4_1 -sse4_2 -ssse3" ELIBC="-FreeBSD" PYTHON_TARGETS="python2_7 python3_6 -python3_5 -python3_7")
     Homepage:            https://opencv.org
     Description:         A collection of algorithms and sample code for various computer vision problems

`

````
Python 3.6.9 (default, Nov 24 2019, 03:26:07) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'

````

Cv2 was working fine a week ago.
Comment 1 Jonas Stein gentoo-dev 2019-12-25 16:36:20 UTC
Thank you for the report. Please recompile and 
*attach* the logfiles and 
paste the emerge info as described on
https://wiki.gentoo.org/wiki/Attach_the_logs_to_the_bug_ticket
We need to have all information at hand before ticket assignment, so that the maintainer can look after it in one session with minimal number of callbacks.
Please reopen this ticket (Status:unconfirmed) afterwards.
Comment 2 Hendrik Klug 2019-12-25 18:27:53 UTC
Created attachment 600604 [details]
build log of emerge media-libs/opencv
Comment 3 Hendrik Klug 2019-12-25 18:29:57 UTC
emerge --info media-libs/opencv :


Portage 2.3.81 (python 3.6.9-final-0, default/linux/amd64/17.1/desktop/gnome/systemd, gcc-8.3.0, glibc-2.30-r3, 5.3.11-gentoo x86_64)
=================================================================
                         System Settings
=================================================================
System uname: Linux-5.3.11-gentoo-x86_64-Intel-R-_Xeon-R-_CPU_E5-2630_v4_@_2.20GHz-with-gentoo-2.6
KiB Mem:   131926868 total,  10206280 free
KiB Swap:  131071996 total, 129316348 free
Timestamp of repository gentoo: Wed, 11 Dec 2019 16:00:01 +0000
Head commit of repository gentoo: 185c0c46a8e90f24117ab52c06be496e99a4591d
Head commit of repository science: d7c83c94da820078b789db52bbcc9ac12d7538ef

sh bash 5.0_p11
ld GNU ld (Gentoo 2.33.1 p1) 2.33.1
app-shells/bash:          5.0_p11::gentoo
dev-java/java-config:     2.2.0-r4::gentoo
dev-lang/perl:            5.30.1::gentoo
dev-lang/python:          2.7.17::gentoo, 3.6.9::gentoo, 3.7.5-r1::gentoo
dev-util/cmake:           3.16.1::gentoo
sys-apps/baselayout:      2.6-r1::gentoo
sys-apps/sandbox:         2.18::gentoo
sys-devel/autoconf:       2.13-r1::gentoo, 2.69-r5::gentoo
sys-devel/automake:       1.16.1-r2::gentoo
sys-devel/binutils:       2.33.1::gentoo
sys-devel/gcc:            8.3.0-r3::gentoo, 9.2.0-r2::gentoo
sys-devel/gcc-config:     2.1::gentoo
sys-devel/libtool:        2.4.6-r5::gentoo
sys-devel/make:           4.2.1-r4::gentoo
sys-kernel/linux-headers: 5.4::gentoo (virtual/os-headers)
sys-libs/glibc:           2.30-r3::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000
    sync-rsync-verify-max-age: 24
    sync-rsync-extra-opts: 
    sync-rsync-verify-jobs: 1
    sync-rsync-verify-metamanifest: yes

science
    location: /var/lib/overlays/science
    sync-type: git
    sync-uri: git://git.gentoo.org/proj/sci.git
    masters: gentoo

chymeric
    location: /home/chymera/src/overlay
    masters: gentoo
    priority: 8889

ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="*"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=native -O2 -pipe"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-march=native -O2 -pipe"
DISTDIR="/usr/portage/distfiles"
EMERGE_DEFAULT_OPTS="--keep-going"
ENV_UNSET="DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"
FCFLAGS="-march=native -O2 -pipe"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch pid-sandbox preserve-libs protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-march=native -O2 -pipe"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="en_GB.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j20"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
USE="X a52 aac acl acpi alsa amd64 berkdb bluetooth branding bzip2 cairo cdda cli colord crypt cups cxx dbus dri dts dvd dvdr eds emboss encode evo exif fam fat flac fortran gdbm gif gnome gnome-keyring gnome-online-accounts gpm gstreamer gtk iconv icu introspection ipv6 jpeg latex lcms ldap libnotify libsecret libtirpc mad mng mp3 mp4 mpeg multilib nautilus ncurses networkmanager nls nptl ntfs ogg opengl openmp pam pango pcre pdf png policykit ppds pulseaudio python readline science sdl seccomp spell split-usr ssl startup-notification svg systemd tcpd tiff tracker truetype udev udisks unicode upower usb vorbis wxwidgets x264 xattr xcb xml xv xvid zlib" ABI_X86="64" ADA_TARGET="gnat_2018" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="mmx mmxext sse sse2" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" GRUB_PLATFORMS="efi-64" INPUT_DEVICES="libinput keyboard mouse" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" NETBEANS_MODULES="apisupport cnd groovy gsf harness ide identity j2ee java mobility nb php profiler soa visualweb webcommon websvccommon xml" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-2" POSTGRES_TARGETS="postgres10 postgres11" PYTHON_SINGLE_TARGET="python3_6" PYTHON_TARGETS="python2_7 python3_6" RUBY_TARGETS="ruby24 ruby25" USERLAND="GNU" VIDEO_CARDS="nvidia" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CC, CPPFLAGS, CTARGET, CXX, INSTALL_MASK, LC_ALL, LINGUAS, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS

=================================================================
                        Package Settings
=================================================================

media-libs/opencv-4.1.2-r2::gentoo was built with the following:
USE="eigen features2d gstreamer gtk jpeg opengl openmp png python tiff -contrib -contribcvv -contribdnn -contribhdf -contribsfm -contribxfeatures2d -cuda -debug -dnnsamples -download -examples -ffmpeg -gdal -gflags -glog -gphoto2 -ieee1394 -java -jpeg2k -lapack -libav -opencl -opencvapps -openexr -pch -qt5 -tesseract -testprograms -threads -v4l -vaapi -vtk -webp -xine" ABI_X86="(64) -32 (-x32)" CPU_FLAGS_X86="sse sse2 -avx -avx2 -fma3 -popcnt -sse3 -sse4_1 -sse4_2 -ssse3" PYTHON_TARGETS="python2_7 python3_6 -python3_5 -python3_7"
Comment 4 Zitian Li 2019-12-30 15:39:41 UTC
Created attachment 601900 [details, diff]
opencv-4.1.2-python-lib-suffix-hack.patch
Comment 5 Tiago Resende 2020-01-23 00:42:37 UTC
Both the ebuilds for opencv-4.1.2-r1 and 4.1.2-r2 seem to disable building python modules in multilib_src_configure() by appending these cmake arguments:

-DBUILD_opencv_python2=OFF
-DBUILD_opencv_python3=OFF

Versions 2.4.13-r3 and 3.4.1-r7 are not affected since their ebuilds don't contain those lines. Commenting them fixed the issue for me, though I also had to apply the opencv-4.1.2-python-lib-suffix-hack.patch attached by Zitian Li for the modules to be installed to /usr/lib64 rather than /usr/lib.
Comment 6 Tiago Resende 2020-01-23 00:44:10 UTC
Created attachment 604028 [details, diff]
ebuild patch to re-enable the python modules
Comment 7 Judge Dredd 2020-03-07 05:15:47 UTC
It's still there with 3.4.1-r7.
Comment 8 Judge Dredd 2020-03-09 01:01:43 UTC
Created attachment 617586 [details, diff]
Fix for opencv-3.4.1-r7 to build with python bindings

This patch seems to fix the problem for me (opencv-3.4.1-r7)
Comment 9 Tiago Resende 2020-05-21 19:05:11 UTC
I'm revisiting this ebuild and noticed a glaring mistake I had made last time, which was to accidentally disable the python USE flag for opencv, which caused the ebuild's python_module_compile() function not to run and therefore the python modules not to get built. Then, by hacking the cmake arguments in multilib_src_configure(), I caused them to be built and installed anyway, despite the missing USE flag.

I apologize for polluting this bug report and ask that everyone please disregard my previous comment and patch.