TypeError: cannot pickle 'fortran' object

Hi. Thanks for the reply. Yes, the code worked fine with cores=1. I had PyMC installed via pip.

I’ve somehow managed to get myself into a state where the clang in my environment cannot find unistd.h (sometimes stdio.h), though I have no idea how. When I run the installation instructions you point to, making a brand new env and then running this simple pymc code pymctest.py · GitHub (taken from GLM: Linear regression — PyMC 5.6.1 documentation) I get errors such as:

pytensor.link.c.exceptions.CompileError: Compilation failed (return status=1):
/Users/terry/miniconda3/envs/pymc_env/bin/clang++ -dynamiclib -g -Wno-c++11-narrowing -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -m64 -fPIC -undefined dynamic_lookup -I/Users/terry/miniconda3/envs/pymc_env/lib/python3.11/site-packages/numpy/core/include -I/Users/terry/miniconda3/envs/pymc_env/include/python3.11 -I/Users/terry/miniconda3/envs/pymc_env/lib/python3.11/site-packages/pytensor/link/c/c_code -L/Users/terry/miniconda3/envs/pymc_env/lib -fvisibility=hidden -o /Users/terry/.pytensor/compiledir_macOS-13.4.1-x86_64-i386-64bit-i386-3.11.4-64/lazylinker_ext/lazylinker_ext.so /Users/terry/.pytensor/compiledir_macOS-13.4.1-x86_64-i386-64bit-i386-3.11.4-64/lazylinker_ext/mod.cpp
In file included from /Users/terry/.pytensor/compiledir_macOS-13.4.1-x86_64-i386-64bit-i386-3.11.4-64/lazylinker_ext/mod.cpp:1:
In file included from /Users/terry/miniconda3/envs/pymc_env/lib/python3.11/site-packages/pytensor/link/c/c_code/pytensor_mod_helper.h:4:
In file included from /Users/terry/miniconda3/envs/pymc_env/include/python3.11/Python.h:23:
/Users/terry/miniconda3/envs/pymc_env/bin/../include/c++/v1/stdlib.h:150:34: error: unknown type name 'ldiv_t'
inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {
                                 ^
/Users/terry/miniconda3/envs/pymc_env/bin/../include/c++/v1/stdlib.h:151:12: error: no member named 'ldiv' in the global namespace
  return ::ldiv(__x, __y);
         ~~^
/Users/terry/miniconda3/envs/pymc_env/bin/../include/c++/v1/stdlib.h:154:34: error: unknown type name 'lldiv_t'
inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
                                 ^
/Users/terry/miniconda3/envs/pymc_env/bin/../include/c++/v1/stdlib.h:156:12: error: no member named 'lldiv' in the global namespace
  return ::lldiv(__x, __y);
         ~~^
In file included from /Users/terry/.pytensor/compiledir_macOS-13.4.1-x86_64-i386-64bit-i386-3.11.4-64/lazylinker_ext/mod.cpp:1:
In file included from /Users/terry/miniconda3/envs/pymc_env/lib/python3.11/site-packages/pytensor/link/c/c_code/pytensor_mod_helper.h:4:
In file included from /Users/terry/miniconda3/envs/pymc_env/include/python3.11/Python.h:26:
/Users/terry/miniconda3/envs/pymc_env/bin/../include/c++/v1/string.h:95:102: error: unknown type name 'size_t'
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD const void* memchr(const void* __s, int __c, size_t __n) {
                                                                                                     ^
/Users/terry/miniconda3/envs/pymc_env/bin/../include/c++/v1/string.h:98:90: error: unknown type name 'size_t'
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_PREFERRED_OVERLOAD void* memchr(void* __s, int __c, size_t __n) {
                                                                                         ^
In file included from /Users/terry/.pytensor/compiledir_macOS-13.4.1-x86_64-i386-64bit-i386-3.11.4-64/lazylinker_ext/mod.cpp:1:
In file included from /Users/terry/miniconda3/envs/pymc_env/lib/python3.11/site-packages/pytensor/link/c/c_code/pytensor_mod_helper.h:4:
/Users/terry/miniconda3/envs/pymc_env/include/python3.11/Python.h:29:12: fatal error: 'unistd.h' file not found
#  include <unistd.h>
           ^~~~~~~~~~
7 errors generated.

Sorry for the long output. This happens whether I use Python 3.10 or 3.11 and whether I use conda or mamba.

So I’m a bit stuck. When I use brew to install clang, its version of clang has no problem compiling a tiny C program that #includes unistd.h. But the clang in my conda environment fails to find the header. I’ve been looking (for many hours now) online to see if I can find a solution, without success (there are of course many such errors for various packages going back many years).

Thanks again!