bcc: ImportError: cannot import name BPF

4.9.0-8-amd64 #1 SMP Debian 4.9.144-3 (2019-02-02) x86_64 GNU/Linux

After following the installation instructions for Debian here: https://github.com/iovisor/bcc/blob/master/INSTALL.md#debian---source

I am unable to run any of the tools. They all fail with the error message:

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

Here are my current kernel BPF configs:

cat /boot/config-4.9.0-8-amd64 | grep BPF
CONFIG_BPF=y
CONFIG_BPF_SYSCALL=y
# CONFIG_BPF_JIT_ALWAYS_ON is not set
CONFIG_NETFILTER_XT_MATCH_BPF=m
CONFIG_NET_CLS_BPF=m
CONFIG_NET_ACT_BPF=m
CONFIG_BPF_JIT=y
CONFIG_HAVE_EBPF_JIT=y
CONFIG_BPF_EVENTS=y
CONFIG_TEST_BPF=m

Any help would be appreciated.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 15
  • Comments: 15 (1 by maintainers)

Most upvoted comments

use 'apt install python3-bpfcc ’ , ‘pip3 install bcc’ not works

You need to install python-bcc or python3-bcc

I had this problem but managed to make it disappear with pip3 uninstall bcc

I met a similar issue:

Traceback (most recent call last):
  File "/path/of/bitehist.py", line 17, in <module>
    from bcc import BPF
ImportError: cannot import name 'BPF' from 'bcc' (/opt/python/3.9.6/lib/python3.9/site-packages/bcc/__init__.py)

And I fixed it with:

export PYTHONPATH=$(dirname `find /usr/lib -name bcc`):$PYTHONPATH

The fix is from: https://github.com/iovisor/bcc/blob/master/FAQ.txt#L17

Try running it with ‘sudo su’ - image

use 'apt install python3-bpfcc ’ , ‘pip3 install bcc’ not works

Look at Install.md file. You may need to build bcc with PYTHON_CMD option like

cmake .. -DPYTHON_CMD=python3 # for python3 support