Broker & Python 3

I just compiled Broker and getting errors with python3x. Here’s the output.

python3 -c ‘import broker; print(broker.file)’

Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘broker’

python3.6 -c ‘import broker; print(broker.file)’

Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘broker’

Is this my system or something in the Broker build?

That error is saying Python can't locate the broker module, so the
general thing you need to do is figure out why it can't locate it.

First thing to check would be if the Python bindings are being built
at all. Does the summary of ./configure say "Python bindings: yes" ?

If they're built, then it also depends on whether you're installing it
or trying to run from the build directory ? If you're installing it,
are you doing it as part of a Bro/Zeek install or separately on its
own ?

If you're not installing, then you need to tell Python where to locate
it within the build directory:

$ PYTHONPATH=./build/python python3 -c 'import broker; print(broker.__file__)'
/Users/jon

If you're installing as part of Bro/Zeek, it's likely not installed at
a path where Python will locate it by default:

$ PYTHONPATH=/usr/local/zeek/lib/zeekctl python3 -c 'import broker;
print(broker.__file__)'
/usr/local/zeek/lib/zeekctl/broker/__init__.py

If you're installing Broker by itself, then it may choose a standard
place where it will be located by Python by default (e.g.
site-packages), but really depends on your system and how Broker is
configured, so might help to get more details from the output of your
./configure

- Jon

Broker was installed with Bro. Python wasn’t working so it was installed via source also. Python 2.7 bindings was installed in the right place. But Python3.6 didn’t install right. I’m not seeing broker in any python3.x folder.

python2.7 -c ‘import broker; print(broker.file)’

/usr/lib/python2.7/dist-packages/broker/init.pyc

python2 -c ‘import broker; print(broker.file)’

/usr/lib/python2.7/dist-packages/broker/init.pyc

python3 -c ‘import broker; print(broker.file)’

Traceback (most recent call last):
File “”, line 1, in
AttributeError: module ‘broker’ has no attribute ‘file

python3.6 -c ‘import broker; print(broker.file)’

Traceback (most recent call last):
File “”, line 1, in
AttributeError: module ‘broker’ has no attribute ‘file

Any given build/install of Broker only picks a single version of
Python for which to provide bindings. The output of ./configure tells
you which one (likely whatever is first in your PATH). There's also
the --with-python= and --with-python-config options if you need them.

- Jon