achow101 / coin-selection-simulation

13 stars 5 forks source link

ImportError: cannot import name 'BPF' from 'bcc' #15

Closed remyers closed 10 months ago

remyers commented 10 months ago

I get this error: cannot import name 'BPF' from 'bcc' trying to run on Ubuntu 22.04.3 LTS (22.04).

remyers commented 10 months ago

It seems the correct solution for Ubuntu 22.04 is to build bcc from scratch, but that required a few changes to the CMakeList.txt file based on similar issues mentioned in the bcc project.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 18407e86..e981e795 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -128,7 +128,7 @@ if(CMAKE_USE_LIBBPF_PACKAGE)
 endif()

 if(NOT PYTHON_ONLY)
-  find_package(LLVM REQUIRED CONFIG)
+  find_package(LLVM 14 REQUIRED CONFIG)
   message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIRS} ${LLVM_PACKAGE_VERSION} (Use LLVM_ROOT envronment variable for another version of LLVM)")

   if(ENABLE_CLANG_JIT)
@@ -144,7 +144,7 @@ if(NOT PYTHON_ONLY)

     # clang is linked as a library, but the library path searching is
     # primitively supported, unlike libLLVM
-    set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-3.7/lib;${LLVM_LIBRARY_DIRS}")
+    set(CLANG_SEARCH "/opt/local/llvm/lib;/usr/lib/llvm-14/lib;${LLVM_LIBRARY_DIRS}")
remyers commented 10 months ago

I also had to uninstall the bcc installed by default in Ubunutu and located in /usr/lib/python3/dist-packages/bcc. I renamed the folder to bcc.old, but there might be a cleaner way to uninstall it that I couldn't figure out.

Hopefully this helps someone else on Ubuntu that isn't a bcc guru to run these great simulations.