Skip to content

Python: some packages don't propagate python causing "nix-shell -p" to fail #17679

@olejorgenb

Description

@olejorgenb

Steps to reproduce

Example:

nix-shell -p python2Packages.pycairo
echo $PYTHONPATH
# empty
exit

nix-shell -p python2Packages.pycairo python2
echo $PYTHONPATH
# <snip>:/nix/store/*-python2.7-pycairo-1.10.0/lib/python2.7/site-packages

Technical details

It's the setup-hook of the python package that set PYTHONPATH. If a package doesn't propagate (propagatedBuildInputs) python, the envHook wont run and the package wont be usable from the shell. (unless python is explicitly added also)

I talked to @domenkozar on IRC, and the policy is that all python packages should be usable without explicitly specifying python too.

I've created a script that finds packages that might break this principle.

The script isn't perfect so the candidates must be checked manually.

I've identified the following python 2 packages so far: [1] (attribute names under python2Packages)

  • PyXML
  • PyXAPI
  • bsddb
  • crypt
  • curses_panel
  • dbus
  • gdbm
  • gst-python
  • libvirt
  • notify
  • pyblock
  • pycairo
  • pygobject
  • pygobject3
  • pygtksourceview
  • pyside
  • pysvn
  • pywebkitgtk
  • qscintilla
  • recursivePthLoader
  • sip
  • sip_4_16
  • readline (*)
  • curses (*)
  • sqlite3 (*)

(*) These are importable without PYTHONPATH (native modules?), but with --pure the python interpreter is not available

To prevent this error in the future a note should be added to the nixpkgs manual? Something like:

Python packages should propagate python (through propagatedBuildInputs such that nix-shell -p pkg works. buildPythonPackages does this automatically.

Maybe it's even possible to add a test?

  • System: NixOS: 16.03.948.a96c308 (Emu)
  • Nix version: nix-env (Nix) 1.11.2
  • Nixpkgs version: "16.09pre88185.52a875f" (not my system, but the version I ran my detection script against)

[1] by doing (against nixos stable though, so some might have been fixed in master in a way that "fools" my script, and I've omitted the master-only candidates)

check() {
    nix-shell --run "echo $PYTHONPATH" -p python2Package.$1
    nix-shell --run "echo $PYTHONPATH" -p python2Package.$1 python2
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bugSomething is broken6.topic: pythonPython is a high-level, general-purpose programming language.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions