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

2.a) create requirements.txt file


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

  1. edit pyproject.toml

Line #111 [Afhel]


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


  • {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

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

#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'
            return '.a'
    else:  # shared
        if platform_system == 'Windows':
            return '.dll'
        elif platform_system == 'Darwin':
        	return '.dylib'
            return '.so'

Build and install:

% python3 build
% pip 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.