tutorials icon indicating copy to clipboard operation
tutorials copied to clipboard

ModuleNotFoundError: No module named 'p4.tmp'

Open nagmat1 opened this issue 3 years ago • 8 comments

I have installed the p4 and behavior model as mentioned on tutorial. When I execute make build on basic folder. It executes normally :

mkdir -p build pcaps logs
p4c-bm2-ss --p4v 16 --p4runtime-files build/basic.p4.p4info.txt -o build/basic.json basic.p4

But when I am trying to run the program make run, I am getting this error :

mkdir -p build pcaps logs
p4c-bm2-ss --p4v 16 --p4runtime-files build/basic.p4.p4info.txt -o build/basic.json basic.p4
sudo python3 ../../utils/run_exercise.py -t pod-topo/topology.json -j build/basic.json -b simple_switch_grpc
Traceback (most recent call last):
  File "../../utils/run_exercise.py", line 28, in <module>
    import p4runtime_lib.simple_controller
  File "/home/nnazarov/deneme/p4c/build/tutorials/utils/p4runtime_lib/simple_controller.py", line 24, in <module>
    from . import bmv2, helper
  File "/home/nnazarov/deneme/p4c/build/tutorials/utils/p4runtime_lib/bmv2.py", line 15, in <module>
    from p4.tmp import p4config_pb2
ModuleNotFoundError: No module named 'p4.tmp'
make: *** [../../utils/Makefile:35: run] Error 1

What may be the problem?

nagmat1 avatar Apr 08 '22 20:04 nagmat1

@nagmat1 The p4.tmp module is provided by https://github.com/p4lang/PI

rst0git avatar Apr 09 '22 12:04 rst0git

You wrote "I have installed the p4 and behavior model as mentioned on tutorial."

Did you execute these commands to install it?

git clone https://github.com/p4lang/tutorials
cd tutorials/vm-ubuntu-20.04
vagrant up

If not, what commands did you use?

I test the commands above about once per month, and the last time I did, it did not have the problem you described.

jafingerhut avatar Apr 09 '22 17:04 jafingerhut

You wrote "I have installed the p4 and behavior model as mentioned on tutorial."

Did you execute these commands to install it?

git clone https://github.com/p4lang/tutorials
cd tutorials/vm-ubuntu-20.04
vagrant up

If not, what commands did you use?

I test the commands above about once per month, and the last time I did, it did not have the problem you described.

I am not using VM, I have installed on my PC.

nagmat1 avatar Apr 09 '22 17:04 nagmat1

"I have installed on my PC." Do you mean a computer running some version of the Windows OS? That is probably one of the least tested platforms for running the open source P4 development tools. Ubuntu Linux is #1, some other Linux distros are #2, macOS is #3 and has some quirks, and I do not think Windows even makes the list, in terms of number of users.

I would recommend running a Linux VM on Windows, if you want to use a Windows system. That is much better supported in terms of things that have been well tested with P4 open source dev tools.

jafingerhut avatar Apr 09 '22 18:04 jafingerhut

No, the OS is Ubuntu 20.04,

I tried to install some other P4 code from other tutorial and both of them crashed I guess.

nagmat1 avatar Apr 09 '22 18:04 nagmat1

So if you can give exactly which sequence of commands you used to try to install the P4 development tools, and ideally also save the output from those commands (since sometimes one can find where things went wrong by looking through such output), which OS you are using, etc., someone might be able to help you. But "hey, it did not work" is not nearly enough information to go on. (Yes, I know you gave a particular error message you are experiencing in the original issue, but if you want to know why it is giving that error, versus other ways of installing the P4 dev tools that do not give that error, more details are useful.)

jafingerhut avatar Apr 09 '22 20:04 jafingerhut

I resolved the issue. I am using Ubuntu 20.04. After executing make run, I was getting :

p4c-bm2-ss --p4v 16 --p4runtime-files build/basic.p4.p4info.txt -o build/basic.json basic.p4
sudo python3 ../../utils/run_exercise.py -t pod-topo/topology.json -j build/basic.json -b simple_switch_grpc
Traceback (most recent call last):
  File "../../utils/run_exercise.py", line 33, in <module>
    import p4runtime_lib.simple_controller
  File "/home/nnazarov/mysde/tutorials/utils/p4runtime_lib/simple_controller.py", line 22, in <module>
    from . import bmv2
  File "/home/nnazarov/mysde/tutorials/utils/p4runtime_lib/bmv2.py", line 15, in <module>
    from .switch import SwitchConnection
  File "/home/nnazarov/mysde/tutorials/utils/p4runtime_lib/switch.py", line 22, in <module>
    from p4.tmp import p4config_pb2
ModuleNotFoundError: No module named 'p4.tmp'
make: *** [../../utils/Makefile:35: run] Error 1

When I locate p4config_pb2 : I can see that :

usr/lib/python3/dist-packages/p4/tmp/p4config_pb2.py
/usr/lib/python3/dist-packages/p4/tmp/p4config_pb2_grpc.py
/usr/lib/python3/dist-packages/p4/tmp/__pycache__/p4config_pb2.cpython-38.pyc
/usr/lib/python3/dist-packages/p4/tmp/__pycache__/p4config_pb2_grpc.cpython-38.pyc
/usr/local/lib/python2.7/dist-packages/p4/tmp/p4config_pb2.py
/usr/local/lib/python2.7/dist-packages/p4/tmp/p4config_pb2.pyc
/usr/local/lib/python2.7/dist-packages/p4/tmp/p4config_pb2.pyo
/usr/local/lib/python2.7/dist-packages/p4/tmp/p4config_pb2_grpc.py
/usr/local/lib/python2.7/dist-packages/p4/tmp/p4config_pb2_grpc.pyc
/usr/local/lib/python2.7/dist-packages/p4/tmp/p4config_pb2_grpc.pyo

but somehow python was not getting the exact path. Maybe not the best solution but I copied cp -r /usr/lib/python3/dist-packages/p4/ ~/mysde/tutorials/utils/ and it resolved the issue.

Thank you guys for taking your time and helping me resolve the issue.

nagmat1 avatar Apr 09 '22 21:04 nagmat1

Oh! Thank you very much. I had the same problem and I solved it according to your solution!!

KekeZheng avatar Aug 18 '22 10:08 KekeZheng

Oh! Thank you very much. I had the same problem and I solved it according to your solution!!!

PengZhan1998 avatar Feb 26 '23 17:02 PengZhan1998

I resolved the issue. I am using Ubuntu 20.04. After executing make run, I was getting :

p4c-bm2-ss --p4v 16 --p4runtime-files build/basic.p4.p4info.txt -o build/basic.json basic.p4
sudo python3 ../../utils/run_exercise.py -t pod-topo/topology.json -j build/basic.json -b simple_switch_grpc
Traceback (most recent call last):
  File "../../utils/run_exercise.py", line 33, in <module>
    import p4runtime_lib.simple_controller
  File "/home/nnazarov/mysde/tutorials/utils/p4runtime_lib/simple_controller.py", line 22, in <module>
    from . import bmv2
  File "/home/nnazarov/mysde/tutorials/utils/p4runtime_lib/bmv2.py", line 15, in <module>
    from .switch import SwitchConnection
  File "/home/nnazarov/mysde/tutorials/utils/p4runtime_lib/switch.py", line 22, in <module>
    from p4.tmp import p4config_pb2
ModuleNotFoundError: No module named 'p4.tmp'
make: *** [../../utils/Makefile:35: run] Error 1

When I locate p4config_pb2 : I can see that :

usr/lib/python3/dist-packages/p4/tmp/p4config_pb2.py
/usr/lib/python3/dist-packages/p4/tmp/p4config_pb2_grpc.py
/usr/lib/python3/dist-packages/p4/tmp/__pycache__/p4config_pb2.cpython-38.pyc
/usr/lib/python3/dist-packages/p4/tmp/__pycache__/p4config_pb2_grpc.cpython-38.pyc
/usr/local/lib/python2.7/dist-packages/p4/tmp/p4config_pb2.py
/usr/local/lib/python2.7/dist-packages/p4/tmp/p4config_pb2.pyc
/usr/local/lib/python2.7/dist-packages/p4/tmp/p4config_pb2.pyo
/usr/local/lib/python2.7/dist-packages/p4/tmp/p4config_pb2_grpc.py
/usr/local/lib/python2.7/dist-packages/p4/tmp/p4config_pb2_grpc.pyc
/usr/local/lib/python2.7/dist-packages/p4/tmp/p4config_pb2_grpc.pyo

but somehow python was not getting the exact path. Maybe not the best solution but I copied cp -r /usr/lib/python3/dist-packages/p4/ ~/mysde/tutorials/utils/ and it resolved the issue.

Thank you guys for taking your time and helping me resolve the issue.

I solve the same problem with your sulotion too!Thank you!!

ruirui-wang-study avatar Nov 06 '23 07:11 ruirui-wang-study