2

After building BCC from source and running the test "sudo /usr/share/bcc/tools/execsnoop", I got the following output:

Traceback (most recent call last): File "/usr/share/bcc/tools/execsnoop", line 21, in from bcc import BPF ImportError: No module named bcc

What does this mean and what can be done to remedy it?

After installing the dependencies, these are the steps that I followed:

git clone https://github.com/iovisor/bcc.git
mkdir bcc/build; cd bcc/build
# python2 can be substituted here, depending on your environment
cmake -DPYTHON_CMD=python3 ..
make && sudo make install

sudo /usr/share/bcc/tools/execsnoop #Test
SuperSim135
  • 135
  • 1
  • 10
  • [so] is for programming questions, not questions about using or configuring Unix and its utilities. [unix.se] or [su] would be better places for questions like this. – Barmar Nov 27 '20 at 20:36
  • 2
    My guess would be that you've installed it with one version of python but its trying to run with another – Alan Birtles Nov 27 '20 at 20:38
  • @Barmar This is a programming question. I'm building a library. What I'm essentially asking is why didn't the build process yield the correct result? – SuperSim135 Nov 27 '20 at 20:43
  • @AlanBirtles The build instructions told me to use "cmake -DPYTHON_CMD=python3 ..". Wouldn't this make it use Python 3? – SuperSim135 Nov 27 '20 at 20:45
  • 1
    Every time I've had this issue with bcc it was as @AlanBirtles pointed out: a problem of Python version. Did you try `sudo python3 /usr/share/bcc/tools/execsnoop`? – pchaigno Nov 27 '20 at 21:29
  • @pchaigno Yes this worked! Now it's telling me that I'm missing module headers. – SuperSim135 Nov 27 '20 at 21:48
  • 1
    presumably `/usr/share/bcc/tools/execsnoop` starts with `#!/bin/python`(or similar), change it to `#!/bin/python3` – Alan Birtles Nov 27 '20 at 22:08
  • @AlanBirtles That's correct! After I made that change, I no longer have to put python3 before the command. – SuperSim135 Nov 27 '20 at 23:08

1 Answers1

3

this is caused due to python2 is set as default python.

$ ls -l `which python`
lrwxrwxrwx 1 root root 7 Mar  4  2019 /usr/bin/python -> python2

there is one way to change all occurrences of

#!/usr/bin/python to #!/usr/bin/python3

or

sudo ln -s /usr/bin/python3 /usr/bin/python

or

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 100
update-alternatives: using /usr/bin/python3.7 to provide /usr/bin/python (python) in auto mode

which will change python to alternatives python

$ ls -l `which python`
lrwxrwxrwx 1 root root 24 Nov 29 20:21 /usr/bin/python -> /etc/alternatives/python
Devidas
  • 2,479
  • 9
  • 24