Nixpkgs: Python says it cannot find SetupTools

Created on 22 May 2017  路  8Comments  路  Source: NixOS/nixpkgs

I've installed Python3, python 3 setuptools, and pip.

Whenever I run a pip install or python ./setup I get a complaint that it cannot find module setuptools.

When I pip install setuptools it says its already installed and points to the nix path ( which is probably created by installing setuptools via python35Packages.setuptools.

But my error remains. What is wrong with the default python setup to where it cannot find the modules to import that are being installed by the nix expression?

When I check for 'echo $PYTHONPATH' nothing is returned.

Most helpful comment

Please check the manual on how to use Python on Nix.
https://nixos.org/nixpkgs/manual/#using-python

All 8 comments

I've installed Python3, python 3 setuptools, and pip.

How did you install these? Which version of Nixpkgs?

Within configuration.nix

environment.systemPackages = with pkgs; [
python3Full
python35Packages.pip
python35Packages.setuptools
]

nixos-rebuild switch

Stable branch 17.03

Then I try to install this package: https://github.com/flyingrub/scdl
via the command line per github instructions. Running pip install or python3 ./setup both throw same error message:

Traceback (most recent call last):
File "setup.py", line 4, in
from setuptools import setup, find_packages
ImportError: No module named 'setuptools'

Doesn't matter if I'm sudo or not error is the same.

Please check the manual on how to use Python on Nix.
https://nixos.org/nixpkgs/manual/#using-python

@FRidh: Do you think it would be worth a try to have Python pick up libraries from $NIX_PROFILES? I think the current Python behaviour is highly un-intuitive. When something _is_ installable, either with systemPackages or nix-env, it's weird that it doesn't work. It trips people up.

I think the only people this could possible hurt is advanced users who mix wildly different python modules in their profiles _and_ forget to set/unset $NIX_PROFILES or create a special wrapper that purges impure environment variables for these special development environments. For ordinary use this should be fine. But we will never know unless we try.

@bjornfor I'm up for ideas and proposals on how to make it better usable, like perhaps using $NIX_PROFILES. I don't know how that should be done though, and I am not really that interested in it either because in my opinion python.withPackages works fine.

@FRidh: In technical terms, I was thinking just iterating over $NIX_PROFILES in sitecustomize.py and appending $profile/lib/python2.7/site-packages to sys.path (as appropriate for each interpreter).

I really think that's asking for trouble. If you have one version of the interpreter along with packages installed in systemPackages, and then another, ABI-incompatible one, installed with nix-env, then you're going to get some funny errors. This is quite a realistic scenario since what you install with nix-env doesn't have to be of the same channel/version as what you install globally.

You only get funny errors iff the abi compatible version loads the other version's modules. And that only happens for plugins, not for hardcoded dependencies. (Paths from $NIX_PROFILES must be appended, not prefixed, to python search path.) So for normal apps you can have as different abi as you like, AFAICS.

I'm not arguing that there won't ever be cases where you get a crash, but I think the convenience of loading modules from $NIX_PROFILES may outweigh the occasional problems.

Anyway, a simple compromise is to make this opt-in. I.e. reading $NIX_PROFILES only happens if $NIX_PYTHON_USE_PROFILES is set, or something like that. Then people like me can set that one flag and have working impure envs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tomberek picture tomberek  路  3Comments

chris-martin picture chris-martin  路  3Comments

matthiasbeyer picture matthiasbeyer  路  3Comments

lverns picture lverns  路  3Comments

yawnt picture yawnt  路  3Comments