Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cython: zmq_compat.h Cannot open include file: 'zmq.h': No such file or directory #1826

Open
mattia-donato opened this issue Jan 18, 2023 · 4 comments

Comments

@mattia-donato
Copy link

mattia-donato commented Jan 18, 2023

pyzmq version: 25.0.0
libzmq version: 4.3.4
Python version: 3.10 (venv) on Windows 10

In my project due to performance issues I need to use the low-level C calls.
In the pyzmq be possible to use as in the cimport zmq.backend.cython.libzmq as shown in the example "pyzmq/examples/cython/".

The setup.py:

from setuptools import find_packages, setup
from distutils.extension import Extension
from distutils.core import setup
from Cython.Build import cythonize
from Cython.Distutils import build_ext
import numpy as np
import zmq

# COMMAND TO COMPILE: python setup.py build_ext --inplace

include_dirs = [np.get_include()]+zmq.get_includes()+zmq.get_library_dirs()]

print(include_dirs)

print()
setup(
    ext_modules = cythonize([Extension("myproject.libs.cython.fastconverter",
                                       ["myproject/libs/cython/fastconverter.pyx"]),
                             Extension("myproject.libs.cython.ni_fpga_fi.ni_fpga_fi",
                                       ["myproject/libs/cython/ni_fpga_fi/ni_fpga_fi.pyx"]),
                             ],
                             language_level = 3, annotate=True),
    include_dirs=include_dirs,
    packages=find_packages()
)

After the compilation done with the command

python .\setup.py build_ext --inplace

I get the error:

C:\myproject\venv\lib\site-packages\zmq\utils\zmq_compat.h(20): fatal error C1083: Cannot open include file: 'zmq.h': No such file or directory

I thought to change the include_dirs in the setup.py but actually "zmq.h" do not exist in anywhere in the python site-packages.

I installed pyzmq by using simply:

pip install pyzmq

Is there some options that I can use to install PyZmq keeping the file zmq.h somewhere?

Thanks and
Ciao

@minrk
Copy link
Member

minrk commented Jan 18, 2023

pyzmq installs don't redistribute zmq.h (maybe they should!), so you'll need to get it from libzmq itself during your build process.

This is related to #1412 and #986 where a pyzmq install on its own really does not provide enough information to compile against libzmq. In particular: the libzmq name, which may be mangled by auditwheel, and zmq.h. Not sure if there's anything else needed.

@mattia-donato
Copy link
Author

Thank you minrk for your quick answer!
I tried to copy the zmq.h but of course it is not enough because the linker is complaining: I do not have the static libraries (.lib) neither the definition (.def) but I have only the dynamic libraries (.dll).

BTW The reason why I am trying to cimport libzmq in my cython code is due to performance. Unfortunately the cython methods, of the backend of pyzmq, are not always "nogil".

@minrk
Copy link
Member

minrk commented Jan 19, 2023

Ah, if you're on Windows that's a lot more complicated and I've no idea how to do it.

And yes, the Cython classes mostly have gil-holding methods, since they deal with Python objects. You'll want to use the libzmq C API (exposed in pyzmq's libzmq.pxd) to actually do gil-free send/recv.

@NazimHAli
Copy link

+1 running into the same error now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants