iovisor / bcc

BCC - Tools for BPF-based Linux IO analysis, networking, monitoring, and more
Apache License 2.0
20.22k stars 3.84k forks source link

ImportError: cannot import name BPF #2278

Closed britchey80 closed 1 year ago

britchey80 commented 5 years ago

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.

BradWalker commented 5 years ago

I also encounter this same issue on Ubuntu 18.04 when using the installed tools..

bwalker@brads-T460s:~$ apt list --installed | grep bpfcc-tools

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

bpfcc-tools/bionic,bionic,now 0.5.0-5ubuntu1 all [installed]

bwalker@brads-T460s:~$ /usr/sbin/biolatency-bpfcc 
Traceback (most recent call last):
  File "/usr/sbin/biolatency-bpfcc", line 15, in <module>
    from bcc import BPF
ImportError: cannot import name BPF
bwalker@brads-T460s:~$ 
maxdml commented 5 years ago

You need to install python-bcc or python3-bcc

grantseltzer commented 4 years ago

I am still getting this issue

jackice commented 3 years ago

I also encounter this same issue on centos8 when using the installed python3-bcc

dnf list --installed bcc.x86_64 0.11.0-2.el8 @AppStream
bcc-tools.x86_64 0.11.0-2.el8 @AppStream
python3-bcc.x86_64 0.11.0-2.el8 @AppStream

C-h4ck-0 commented 3 years ago

Try running it with 'sudo su' - image

wzhliang commented 3 years ago

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

yueyongyue commented 3 years ago

python2.7 ok python3 unsuccessful

yonghong-song commented 3 years ago

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

cmake .. -DPYTHON_CMD=python3 # for python3 support
MihaiMaties commented 3 years ago

FWIW - in my case it turns out that sudo /bin/python3 /usr/share/bcc/tools/execsnoop works.

python3 resolves (as per $PATH) to ~/.pyenv/shims/python3 in my case - it is 3.8.8 .. same as /usr/bin/python, needed for https://github.com/elastic/rally

/bin/python3 is the "system's" i.e. CentOS 8.3 distribution's 3.6.8

gpstrive commented 3 years ago

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

JiaHuann commented 2 years ago

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

minhtrex commented 2 years ago

I tried on AlmaLinux9. worked: 'sudo yum install python3-bcc ' not worked: 'pip3 install bcc'

gophernancy commented 1 year ago

I also had this problem using python3.9. When I exec "yum install python3", it will install python3.6,it won't this problem.

pangle-zhang commented 1 year ago

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

c0debreaker commented 8 months ago

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

Thanks a lot @pangle-zhang ! That's the only one that made it worked! Thank you so much!