NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.16k stars 14.18k forks source link

bcc: wrong PYTHONPATH #348354

Closed skeggse closed 1 month ago

skeggse commented 1 month ago

Describe the bug

If I nix-shell -p python3 bcc, I cannot import bcc without manually tweaking the PYTHONPATH.

Steps To Reproduce

Steps to reproduce the behavior:

  1. nix-shell -p python3 bcc
  2. python3 -c 'import bcc'
  3. Traceback (most recent call last):
     File "<string>", line 1 in <module>
    ModuleNotFoundError: No module named 'bcc'

Expected behavior

No import error.

Additional context

I can fix this by running:

$ PYTHONPATH="$(cut -d: -f1 <<< "$PYTHONPATH")/$(cat "$(cut -d: -f1 <<< "$PYTHONPATH")/easy-install.pth"):$PYTHONPATH" python3 -c 'import bcc'

Notify maintainers

@ragge @Mic92 @thoughtpolice @martinetd

Metadata

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

[skeggse@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.54, NixOS, 24.05 (Uakari), 24.05.5518.ecbc1ca8ffd6
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.8`
 - channels(root): `"home-manager-24.05.tar.gz, nixos-24.05"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

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

dotlambda commented 1 month ago

Use nix-shell -p "python3.withPackages (ps: [ ps.bcc ])".

Mic92 commented 1 month ago

Explanation: python3.pkgs.bcc != bcc. The first one acts as a python module that will set the python path correctly whereas the later is more like a python application that doesn't pollute PYTHONPATH in case you want to mix it into a python project.

skeggse commented 1 month ago

Hmmm, ok. I guess the explanation kinda makes sense (still trying to figure out this ecosystem), but how do I actually get that to work? The command provided doesn't, and my attempts to integrate it into my shell.nix have also been unsuccessful.

It's worth noting that - to my knowledge - there isn't a bcc package available on pypi.org.

$ nix-shell -p 'python3.withPackages (ps: [ ps.bcc ])'
error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'shell'
         whose name attribute is located at /nix/store/07qksi2rpnqxxl2rbxzgifrfki698rr3-nixos-24.05/nixos/pkgs/stdenv/generic/make-derivation.nix:333:7

       … while evaluating attribute 'buildInputs' of derivation 'shell'

         at /nix/store/07qksi2rpnqxxl2rbxzgifrfki698rr3-nixos-24.05/nixos/pkgs/stdenv/generic/make-derivation.nix:380:7:

          379|       depsHostHost                = elemAt (elemAt dependencies 1) 0;
          380|       buildInputs                 = elemAt (elemAt dependencies 1) 1;
             |       ^
          381|       depsTargetTarget            = elemAt (elemAt dependencies 2) 0;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'bcc' missing

       at «string»:1:135:

            1| {...}@args: with import <nixpkgs> args; (pkgs.runCommandCC or pkgs.runCommand) "shell" { buildInputs = [ (python3.withPackages (ps: [ ps.bcc ])) ]; } ""
             |                                                                                                                                       ^
       Did you mean one of bcf, bcg, bch, bap or bcdoc?
martinetd commented 1 month ago

You need a recent-ish nixos unstable for this to work, the python package was added recently in 05a7a89754284d320157e6c0325e4d8442dbd35b and this was not backported to 24.05

skeggse commented 1 month ago

I see, ok. I'm not on unstable (it's seeming like maybe most NixOS users are on unstable?) and I'd rather not be, so I'll keep my workaround for now.

martinetd commented 4 weeks ago

it's seeming like maybe most NixOS users are on unstable

I mix and match but we've been years without the bcc python package so I think it's more of a "very few people try to actually use bcc" thing.

I see no reason not to backport this now we know someone actually cares about this, so I've opened https://github.com/NixOS/nixpkgs/pull/349088 -- it'll (probably) make it to stable eventually. Until then that workaround is probably a good idea.

Thanks!