Saturday, August 12, 2023

[How To] Install SEAL-Python In macOS


Run the following commands from the Terminal in the given order:

1. brew install cmake autoconf automake libtool shtool gflags

2. xcode-select --install

3. git clone https://github.com/Huelse/SEAL-Python.git

4. cd SEAL-Python

5. pip3 install numpy pybind11

6. git submodule update --init --recursive

7. cd SEAL

8. cmake -S . -B build -DSEAL_USE_MSGSL=OFF -DSEAL_USE_ZLIB=OFF -DSEAL_THROW_ON_TRANSPARENT_CIPHERTEXT=OFF -DCMAKE_C_COMPILER=/usr/local/Cellar/llvm/16.0.1/bin/clang -DCMAKE_CXX_COMPILER=/usr/local/Cellar/llvm/16.0.1/bin/clang++

9. cmake --build build

10. cd ..

11. python3 setup.py build_ext -i

12. cp seal.*.so examples

13. cd examples

14. python3 4_bgv_basics.py

[Solved] Fix "ld: library not found for -lc++" errors in macOS


Linker Error:

Run Build Command(s):/usr/local/Cellar/cmake/3.26.3/bin/cmake -E env VERBOSE=1 /usr/local/bin/gmake -f Makefile cmTC_2eb92/fast && /usr/local/bin/gmake  -f CMakeFiles/cmTC_2eb92.dir/build.make CMakeFiles/cmTC_2eb92.dir/build

    gmake[1]: Entering directory '/Users/devharsh/Downloads/SEAL-Python/SEAL/build/CMakeFiles/CMakeScratch/TryCompile-p29bdr'

    Building CXX object CMakeFiles/cmTC_2eb92.dir/testCXXCompiler.cxx.o

    /Library/Developer/CommandLineTools/usr/bin/c++    -MD -MT CMakeFiles/cmTC_2eb92.dir/testCXXCompiler.cxx.o -MF CMakeFiles/cmTC_2eb92.dir/testCXXCompiler.cxx.o.d -o CMakeFiles/cmTC_2eb92.dir/testCXXCompiler.cxx.o -c /Users/devharsh/Downloads/SEAL-Python/SEAL/build/CMakeFiles/CMakeScratch/TryCompile-p29bdr/testCXXCompiler.cxx

    Linking CXX executable cmTC_2eb92

    /usr/local/Cellar/cmake/3.26.3/bin/cmake -E cmake_link_script CMakeFiles/cmTC_2eb92.dir/link.txt --verbose=1

    /Library/Developer/CommandLineTools/usr/bin/c++ -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/cmTC_2eb92.dir/testCXXCompiler.cxx.o -o cmTC_2eb92 

    ld: library not found for -lc++

    clang: error: linker command failed with exit code 1 (use -v to see invocation)

    gmake[1]: *** [CMakeFiles/cmTC_2eb92.dir/build.make:100: cmTC_2eb92] Error 1

    gmake[1]: Leaving directory '/Users/devharsh/Downloads/SEAL-Python/SEAL/build/CMakeFiles/CMakeScratch/TryCompile-p29bdr'

    gmake: *** [Makefile:127: cmTC_2eb92/fast] Error 2


Solution:

export CPLUS_INCLUDE_PATH=/usr/local/opt/llvm/include/c++/v1:/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/include


export LIBRARY_PATH=$LIBRARY_PATH:/Library/Developer/CommandLineTools/SDKs/MacOSX13.3.sdk/usr/lib

[How To] Create A Python Package


Step 1
- Create src and tests folders and add __init__.py.

(Optionally, you can add docs and scripts directories and other files like CHANGES.txt and MANiFEST.in).

Step 2 - Add modules with functionalities.

Step 3 - Create pyproject.toml and setup.cfg (or setup.py).

Step 4 - Create README.md and LICENSE.txt.

Step 5 - Run the following commands:
pip install --upgrade pip setuptools wheel tqdm twine build

python3 -m build
Step 6 - Create an account on TestPyPi and/or PyPi and generate respective API tokens (alternatively, you can use your account username and password). Use __token__ as username if using API token.

Step 7 
- for TestPyPi - python3 -m twine upload --repository testpypi dist/*
- for PyPi - python3 -m twine upload dist/*

Step 8 - Install and test your package:
pip install <your_package_name>