Hi all,
I’m working on the basic
exercise from the official p4lang/tutorials repo on a clean installation of Ubuntu 24.04 in VirtualBox. I followed the setup steps including:
bash
git clone https://github.com/p4lang/tutorials
cd tutorials/vm-ubuntu-24.04
./install.sh
After that, I went to the exercises/basic
folder and ran:
bash
make run
However, I get the following error:
Traceback (most recent call last):
File "../../utils/run_exercise.py", line 29, in <module>
import p4runtime_lib.simple_controller
File "../../utils/p4runtime_lib/simple_controller.py", line 23, in <module>
from p4.config.v1 import p4info_pb2
ModuleNotFoundError: No module named 'p4'
It seems like the generated p4info_pb2.py
and p4runtime_pb2.py
files are not structured properly for this import to work. What is the correct way to compile the .proto
files so the Python imports work as expected?
Any help or clarification would be greatly appreciated!
Thanks in advance,
Kacper
When you ran ./install.sh
, if everything went successfully, it should have created a file named p4setup.bash
in your home directory. It should also have appended the line source ~/p4setup.bash
at the end of your ~/.bashrc file. Do you see those files, and that line in your ~/.bashrc file?
If so, then if you do anything that causes the ~/.bashrc file to be executed again, then it should add some directories to your command PATH, and do a couple of other useful things. Any of the following will cause the ~/.bashrc to be executed:
- log off, and log back on again. When you log back in, ~/.bashrc should be executed
- reboot your system. When you log in, ~/.bashrc should be executed
- Run the command
source ~/.bashrc
One way to double-check whether the ~/p4setup.bash file has been executed is to show the value of a shell environment variable that it defines, as shown below:
$ echo $P4_EXTRA_SUDO_OPTS
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
If the output is anything other than that, then the p4setup.bash
script has not been executed, and you should figure out why.