Sunday, July 17, 2022

[How To] Install Pyfhel in macOS

 


  • Tested on Intel-based (x86_64) MacBook, not tested on M1/M2 (ARM)
  • Apple Clang does not support -fopenmp and -libseal, use GCC or CLANG
  1. % git clone --recursive https://github.com/ibarrond/Pyfhel

2.a) create requirements.txt file

  "setuptools<=60.9",
  "wheel",
  "cython>=3.0.0a9",
  "numpy>=1.20",
  "cmake>=3.15",
  "toml>=0.10"

2.b) % pip3 install -r requirements.txt

  1. edit pyproject.toml

Line #111 [Afhel]

extra_compile_args

  • {Darwin = ["-std=c++17","-O3","-fopenmp"]},

extra_link_args

  • {Darwin = ["-fopenmp","-dynamiclib"]},

Repeat the above for [CYTHON EXTENSIONS]

  1. edit Pyfhel/Afhel/Afhel.pxd
#from numpy cimport int64_t, uint64_t, uint8_t   

ctypedef long long int64_t
ctypedef unsigned long long uint64_t
ctypedef unsigned char uint8_t
  1. edit Pyfhel/Pyfhel.pxd
#from numpy cimport int64_t, uint64_t

ctypedef long long int64_t
ctypedef unsigned long long uint64_t
  1. edit setup.py

add these lines immediately after imports

os.environ["CC"] = "/usr/local/Cellar/gcc@12/12.1.0_1/bin/gcc-12"
os.environ["CXX"] = "/usr/local/Cellar/gcc@12/12.1.0_1/bin/g++-12"
os.environ["LDSHARED"] = "/usr/local/Cellar/gcc@12/12.1.0_1/bin/g++-12 -Wl,-x -dynamiclib -undefined dynamic_lookup"

Comment Line # 36-38 in setup.py:

#if platform_system == 'Darwin': # MacOS
    #raise SystemError("Pyfhel is not supported in MacOS (see issue #59)."
                      #"Please use a Linux VM or Docker.")

edit # Auxiliary methods

def get_lib_suffix(lib_type: str) -> str:
    if lib_type == 'static':
        if platform_system == 'Windows':
            return '.lib'
        else:
            return '.a'
    else:  # shared
        if platform_system == 'Windows':
            return '.dll'
        elif platform_system == 'Darwin':
        	return '.dylib'
        else:
            return '.so'

Build and install:

% python3 setup.py build && python3 setup.py install  (OR)
% pip3 install .
% cp build/lib.macosx-12-x86_64-3.9/Pyfhel/libAfhel.dylib /usr/local/lib/libAfhel.dylib

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.