Search code examples
pythonc++macospthreadscython

macOS pthread not found


So I am trying to run a framework called COMMIT2 (tractography filtering, does not really matter what it does) which, when ran for their tutorial data runs fine, but when ran for my own data (I guess it uses another function) gives an error. The error occurs in a script calling for:

" #include <pthread.h> " 
Error: /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/commit/operator/operator_withLUT.c:1:10: fatal error: 'pthread.h' file not found #include <pthread.h> ^~~~~~~~~~~ 1 error generated. 

It also gives a very large traceback which I will include below (but the main problem is, as far as I see, in the pthread not found) I am on a macbook and can not really find any real similar problems and/or fixes online so if someone could help me out that would be really appreciated!

----------------- Traceback: Traceback (most recent call last): File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/_distutils/unixccompiler.py", line 185, in _compile self.spawn(compiler_so + cc_args + [src, '-o', obj] + extra_postargs) File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/_distutils/ccompiler.py", line 1041, in spawn spawn(cmd, dry_run=self.dry_run, **kwargs) File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/_distutils/spawn.py", line 70, in spawn raise DistutilsExecError( distutils.errors.DistutilsExecError: command '/usr/local/fsl/bin/clang' failed with exit code 1 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyximport/_pyximport3.py", line 314, in create_module so_path = build_module(spec.name, pyxfilename=spec.origin, pyxbuild_dir=self._pyxbuild_dir, File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyximport/_pyximport3.py", line 197, in build_module so_path = pyxbuild.pyx_to_dll(pyxfilename, extension_mod, File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyximport/pyxbuild.py", line 103, in pyx_to_dll dist.run_commands() File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands self.run_command(cmd) File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/dist.py", line 963, in run_command super().run_command(command) File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/_distutils/dist.py", line 988, in run_command cmd_obj.run() File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/_distutils/command/build_ext.py", line 345, in run self.build_extensions() File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/_distutils/command/build_ext.py", line 467, in build_extensions self._build_extensions_serial() File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/_distutils/command/build_ext.py", line 493, in _build_extensions_serial self.build_extension(ext) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Cython/Distutils/build_ext.py", line 135, in build_extension super(build_ext, self).build_extension(ext) File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/_distutils/command/build_ext.py", line 548, in build_extension objects = self.compiler.compile( File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/_distutils/ccompiler.py", line 600, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/_distutils/unixccompiler.py", line 187, in _compile raise CompileError(msg) distutils.errors.CompileError: command '/usr/local/fsl/bin/clang' failed with exit code 1 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/bkalkhov/Tractography/Tractography_performance_testing/Tests/Commit2test/Own_data/test.py", line 60, in <module> mit.build_operator() File "commit/core.pyx", line 763, in commit.core.Evaluation.build_operator File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyximport/_pyximport3.py", line 332, in create_module raise exc.with_traceback(tb) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyximport/_pyximport3.py", line 314, in create_module so_path = build_module(spec.name, pyxfilename=spec.origin, pyxbuild_dir=self._pyxbuild_dir, File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyximport/_pyximport3.py", line 197, in build_module so_path = pyxbuild.pyx_to_dll(pyxfilename, extension_mod, File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pyximport/pyxbuild.py", line 103, in pyx_to_dll dist.run_commands() File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands self.run_command(cmd) File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/dist.py", line 963, in run_command super().run_command(command) File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/_distutils/dist.py", line 988, in run_command cmd_obj.run() File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/_distutils/command/build_ext.py", line 345, in run self.build_extensions() File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/_distutils/command/build_ext.py", line 467, in build_extensions self._build_extensions_serial() File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/_distutils/command/build_ext.py", line 493, in _build_extensions_serial self.build_extension(ext) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Cython/Distutils/build_ext.py", line 135, in build_extension super(build_ext, self).build_extension(ext) File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/_distutils/command/build_ext.py", line 548, in build_extension objects = self.compiler.compile( File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/_distutils/ccompiler.py", line 600, in compile self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) File "/Users/bkalkhov/Library/Python/3.10/lib/python/site-packages/setuptools/_distutils/unixccompiler.py", line 187, in _compile raise CompileError(msg) ImportError: Building module commit.operator.operator failed: ["distutils.errors.CompileError: command '/usr/local/fsl/bin/clang' failed with exit code 1\n"]

Solution

  • From the traceback it appears that the framework you are using is using is bringing its own compiler (/usr/local/fsl/bin/clang), and it's trying to build a Python extension written in C (presumably to do the heavy lifting in the background) when you invoke it.

    <pthread.h> is a system header on any POSIX-like system (e.g. macOS, Linux), and the fact that it can't find it indicates to me that you don't have any system headers for your macOS system installed, and you wouldn't be able to compile any non-trivial C program on your system.

    I don't know your specific framework and how it is designed internally, but what you could try is to install the XCode Command Line Tools (or even the full XCode development environment) so that the system headers are installed on your system. Whether the custom compiler that is provided in conjunction with the framework you are using is able to find them automatically, I don't know.

    Note: You need an Apple Id to download XCode form Apple via the website, but you can also install it by other means without an Apple id, the easiest I know of is to install Homebrew, which automatically installs the XCode CLI tools.