Python with zmq problem (ImportError:

This is my nix file

{ pkgs ? import {} }:
pkgs.mkShell {
buildInputs = [ pkgs.poetry pkgs.zeromq pkgs.python38 ]; #pkgs.python38.withPackages (p: [p.zmq])
shellHook = ‘’
# fixes libstdc++ issues and issues

in this shell I do

poetry env use 3.8.4
poetry init
poetry add zmq
poetry install
poetry run python

And after that I try to run python script with import zmq and it fails with error:

from . import _zmq
ImportError: cannot open shared object file: No such file or directory

Please help to fix

I’m having the same problem here. From what I’ve researched, the main solution is to use a Nix shell, which I find cumbersome as it does not integrate well with other tools and is not ergonomic. My solution so far has been to run Python on a virtual machine; other methods, such as moving my development environment into a Docker file, have also worked.

@gosup7: I don’t think you can mix “nix management of python packages” and “poetry management of python packages”.

For a shell with python.withPackages, here is an example:

{ pkgs ? import <nixpkgs> {}}:
pkgs.mkShell { packages = [ (pkgs.python3.withPackages (p: [ p.pyzmq ])) ]; }

For a shell with poetry, I would go for GitHub - nix-community/poetry2nix: Convert poetry projects to nix automagically [maintainer=@adisbladis], where pyzmq in particular seems to be supported.

@phsb5321 : I guess you lack proper tooling. One solution that works very well for me is GitHub - nix-community/nix-direnv: A fast, persistent use_nix/use_flake implementation for direnv [maintainer=@Mic92 / @bbenne10]

1 Like