https://github.com/NixOS/nixpkgs/pull/153255
I want a python package to take a opencv4
dependency, but if I put the dependency in propagatedBuildInputs like https://github.com/NixOS/nixpkgs/blob/6aec41eebecce8a296442a71dcfe8727e812914d/pkgs/development/python-modules/cmapy/default.nix#L10 it still complains about missing python-opencv.
How do I say to use opencv for its python-opencv?
austin
January 3, 2022, 1:18am
2
It may be that you are using opencv
when you need the Python package instead.
Maybe try changing to:
fake-background-webcam = callPackage ../applications/video/fake-background-webcam {
opencv = python3Packages.opencv4;
};
I am already building it by nix build .#python3Packages.fake-background-webcam
so it should take the opencv from the python package set
https://github.com/NixOS/nixpkgs/blob/6aec41eebecce8a296442a71dcfe8727e812914d/pkgs/top-level/python-packages.nix#L5557
And yet it does not seem to recognize it.
1 Like
opencv4 is incorrectly packaged:
$ tree $(nix-build '<nixpkgs>' -A python3Packages.opencv4)/lib/python3.9/
/nix/store/dfylw3ppidn6gpbxrkjhmpsazk7cdzdj-opencv-4.5.4/lib/python3.9/
βββ site-packages
βββ cv2.cpython-39-x86_64-linux-gnu.so
There should be some distribution information
$ tree -L 3 $(nix-build '<nixpkgs>' -A python3Packages.requests)/lib/python3.9/
/nix/store/pa8f3ajnj32hp13is72yw8nfcd94bg1w-python3.9-requests-2.26.0/lib/python3.9/
βββ site-packages
βββ requests
....
βββ requests-2.26.0.dist-info
βββ direct_url.json
βββ INSTALLER
βββ LICENSE
βββ METADATA
βββ RECORD
βββ REQUESTED
βββ top_level.txt
βββ WHEEL
Thatβs my suspicion, can you help me with those files?
Iβm creating a PR to fix it for nixpkgs
This was more of a pain than I thought it would be. But hereβs the PR: python3Packages.opencv4: fix installation metadata by jonringer Β· Pull Request #153373 Β· NixOS/nixpkgs Β· GitHub
Couldnβt get it to actually βworkβ
$ nix-shell -E 'with import ./. { }; mkShell { name = "test"; nativeBuildInputs = [ (python3.withPackages (ps: [ps.opencv4])) ]; }'
[nix-shell:~/projects/nixpkgs]$ python
Python 3.9.9 (main, Nov 15 2021, 18:05:17)
[GCC 10.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>
File "/nix/store/b60icklg1rxdjddk8aysg14zyxnb6za0-python3-3.9.9-env/lib/python3.9/site-packages/cv2/__init__.py", line 180, in <module>
bootstrap()
File "/nix/store/b60icklg1rxdjddk8aysg14zyxnb6za0-python3-3.9.9-env/lib/python3.9/site-packages/cv2/__init__.py", line 110, in bootstrap
load_first_config(['config.py'], True)
File "/nix/store/b60icklg1rxdjddk8aysg14zyxnb6za0-python3-3.9.9-env/lib/python3.9/site-packages/cv2/__init__.py", line 108, in load_first_config
raise ImportError('OpenCV loader: missing configuration file: {}. Check OpenCV installation.'.format(fnames))
ImportError: OpenCV loader: missing configuration file: ['config.py']. Check OpenCV installation.
But this appears to be intended behavior, as pyinstaller is required ImportError: OpenCV loader: missing configuration file: ['config.py']. Β· Issue #569 Β· opencv/opencv-python Β· GitHub
Hmm, deleting all of the cv2 python files seems to make it work just fine as a module.
+ # the cv2/__init__.py just tries to check provide "nice user feedback" if the installation is bad
+ # however, this also causes infinite recursion when used by other packages
+ rm -r $out/${pythonPackages.python.sitePackages}/cv2
[11:20:57] jon@nixos ~/projects/nixpkgs (fix-opencv4)
$ nix-shell -E 'with import ./. { }; mkShell { name = "test"; nativeBuildInputs = [ (python3.withPackages (ps: [ps.opencv4])) ]; }'
[nix-shell:~/projects/nixpkgs]$ python
Python 3.9.9 (main, Nov 15 2021, 18:05:17)
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>>
Apparently the module requires opencv-python
,although it is used in the exact same way
interesting, I think thatβs what the directory is called. But thatβs now how they install it.