NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.09k stars 14.14k forks source link

python3*Packages.pymupdf: Runtime import failure in buildEnv #332384

Open mockuser404 opened 3 months ago

mockuser404 commented 3 months ago

Describe the bug

When using nixpkgs stable (nixos-24.05) the packages python312Packages.pymupdf and python311Packages.pymupdf both are not working properly in a nix shell env.

Steps To Reproduce

Steps to reproduce the behavior:

# flake.nix
{
  description = "test pymupdf devshell";
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-24.05";
  };
  outputs =
    { self, nixpkgs, ... }:
    let
      system = "x86_64-linux";
      pkgs = import nixpkgs { inherit system; };
    in
    {
      devShells.${system}.default = pkgs.mkShell {
        packages = [
          (pkgs.python312.withPackages (pp: with pp; [ pymupdf ]))
        ];
      };
    };
}

Now check in the devshell

$ nix develop
$ python
>>> import fitz
Traceback (most recent call last):
  File "/nix/store/qv31saxij43ncc1r2891ck4vnjfav9jz-python3-3.12.4-env/lib/python3.12/site-packages/fitz/__init__.py", line 140, in <module>
    from . import mupdf
ImportError: cannot import name 'mupdf' from partially initialized module 'fitz' (most likely due to a circular import) (/nix/store/qv31saxij43ncc1r2891ck4vnjfav9jz-python3-3.12.4-env/lib/python3.12/site-packages/fitz/__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nix/store/qv31saxij43ncc1r2891ck4vnjfav9jz-python3-3.12.4-env/lib/python3.12/site-packages/fitz/__init__.py", line 142, in <module>
    import mupdf
ModuleNotFoundError: No module named 'mupdf'

Expected behavior

pymupdf gets imported properly since this is approved in nixos stable.

Additional context

Notify maintainers

@teto

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.43, NixOS, 24.11 (Vicuna), 24.11.20240804.5d97d39`
 - multi-user?: `yes`
 - sandbox: `relaxed`
 - version: `nix-env (Nix) 2.18.5`
 - channels(root): `"nixos"`
 - nixpkgs: `/nix/store/x2lvdghyrpvkifz0k910garzbd3wpjdg-source`

Add a :+1: reaction to issues you find important.

mockuser404 commented 3 months ago

I tried the patch from #332385 and it didn't fix this issue. Can someone tell me if this is a real issue or if I'm doing something wrong here. I wish to simply use pymupdf to write some python code on Nixos to extract embedded videos from pdf.

I tried with nixpkgs.url = "github:greg-hellings/nixpkgs?ref=browsr-1.21.0"; and have the same issue.

eclairevoyant commented 3 months ago

python3Packages.pymupdf works, python3.withPackages (p: [ p.pymupdf ]) doesn't.

Can't say I know why though šŸ„²

mockuser404 commented 3 months ago

Thank you. I got it working with

    devShells.${system}.default = pkgs.mkShell {
      venvDir = "./venv";
      buildInputs = with pkgs.python312Packages; [
        venvShellHook
        python
        pymupdf
        icecream
      ];
      # ...
    };

It's not related to #332385 in any way then. I don't know enough nix to debug why this works and why the first doesn't, it is a bug so, I am leaving this issue open even though there is a workaround.

charmoniumQ commented 2 months ago

Addressed by #334596