How to `pyenv install` or equivalent?

Repost from Unix & Linux Stack Exchange:

The original problem:

$ pyenv install
Downloading Python-3.8.10.tar.xz...
-> https://www.python.org/ftp/python/3.8.10/Python-3.8.10.tar.xz
Installing Python-3.8.10...

BUILD FAILED (NixOS 21.05.1555.6b940846e99 using python-build 20180424)

Inspect or clean up the working tree at /tmp/python-build.20210722134513.93343
Results logged to /tmp/python-build.20210722134513.93343.log

Last 10 log lines:
  File "/tmp/python-build.20210722134513.93343/Python-3.8.10/Lib/ensurepip/__init__.py", line 206, in _main
    return _bootstrap(
  File "/tmp/python-build.20210722134513.93343/Python-3.8.10/Lib/ensurepip/__init__.py", line 125, in _bootstrap
    return _run_pip(args + [p[0] for p in _PROJECTS], additional_paths)
  File "/tmp/python-build.20210722134513.93343/Python-3.8.10/Lib/ensurepip/__init__.py", line 34, in _run_pip
    return subprocess.run([sys.executable, "-c", code], check=True).returncode
  File "/tmp/python-build.20210722134513.93343/Python-3.8.10/Lib/subprocess.py", line 516, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/tmp/python-build.20210722134513.93343/Python-3.8.10/python', '-c', '\nimport runpy\nimport sys\nsys.path = [\'/tmp/tmp4bavyai1/setuptools-56.0.0-py3-none-any.whl\', \'/tmp/tmp4bavyai1/pip-21.1.1-py3-none-any.whl\'] + sys.path\nsys.argv[1:] = [\'install\', \'--no-cache-dir\', \'--no-index\', \'--find-links\', \'/tmp/tmp4bavyai1\', \'--root\', \'/\', \'--upgrade\', \'setuptools\', \'pip\']\nrunpy.run_module("pip", run_name="__main__", alter_sys=True)\n']' returned non-zero exit status 1.
make: *** [Makefile:1198: install] Error 1

The log file shows the following error:

ModuleNotFoundError: No module named 'zlib'

The zlib package is installed.

I tried a portable version of this suggestion:

CPPFLAGS="-I$(nix eval --raw nixos.zlib.outPath)/include" LDFLAGS="-L$(nix eval --raw nixos.zlib.outPath)/lib" pyenv install

But that didn’t help. Presumably because there is no “include” directory in the zlib package root. There also doesn’t seem to be any zlib-dev package, so I’m not sure where that is meant to come from.

I’m also open to suggestions involving building a custom derivation, with the caveat that I can’t simply use the “python38” package because the project depends on a specific patch version.

1 Like

There’s usually not a completely-separate package, AFAIK. I think you may just need zlib.dev

The zlib package is installed.

I’m not sure what you meant by “installed”, but if you meant “with nix-env” or “with /etc/configuration.nix” let me point out that on NixOS any compilation related task must be performed in a nix-shell; installing C libraries will usually have no effect. FAQ/I installed a library but my compiler is not finding it. Why? - NixOS Wiki

Try running the command again inside nix-shell -p zlib.

3 Likes

Is there such a package? The package search says it doesn’t exist.

Oh, that’s the article I’ve missed! :slight_smile: Thanks, I’ll need to read that and the nixpkgs Python documentation in detail before I continue. I really hope I’ll be able to wrap the existing dev env rather than reimplementing the whole thing in Nix, though, especially since devs on other platforms will be using the same configuration.

As I said, there usually isn’t a separate package. It’s just a separate “output” (of the single zlib package).

1 Like