p4lang/p4factory

ImportError: cannot import name TFrozenDict

Closed this issue · 6 comments

Hi! Recently I was tring Integration with Mininet.

I followed the step in README, cd the directory p4factory/targets/simple_router/ and make successfully. Then I started the Mininet by the command:

./run_demo.bash
root@ubuntu:/home/wasdns/p4factory/targets/simple_router# ./run_demo.bash
*** Creating network
*** Adding hosts:
h1 h2 
*** Adding switches:
s1 
*** Adding links:
(h1, s1) (h2, s1) 
*** Configuring hosts
h1 h2 
*** Starting controller

*** Starting 1 switches
s1 Starting P4 switch s1
/home/wasdns/p4factory/targets/simple_router/behavioral-model --name s1 --dpid 0000000000000001 -i s1-eth1 -i s1-eth2 --listener 127.0.0.1:11111 --pd-server 127.0.0.1:22222 
switch has been started

**********
h1
default interface: eth0	10.0.0.10	00:04:00:00:00:00
**********
**********
h2
default interface: eth0	10.0.1.10	00:04:00:00:00:01
**********
Ready !
*** Starting CLI:
mininet>

OK, and when I opened another Terminal, cd the directory and tried the command below:

./run_add_demo_entries.bash

to install table entries, I got into trouble:

root@ubuntu:/home/wasdns/p4factory/targets/simple_router# ./run_add_demo_entries.bash 
ImportError: cannot import name TFrozenDict
ImportError: cannot import name TFrozenDict
ImportError: cannot import name TFrozenDict
ImportError: cannot import name TFrozenDict
ImportError: cannot import name TFrozenDict
ImportError: cannot import name TFrozenDict

I'm not familier with Python, but I think it may be something wrong with thrift.

My thrift version:

Thrift version 1.0.0-dev

However..I have no idea about how to deal with it. Should I install the packet named "TFrozenDict"? But I didn't find anything by asking Google.

Can you help me? Thank you. :)

It is an issue with your Thrift installation. There is a discrepancy between your Thrift compiler version and your Thrift python package.
You can check your Thrift compiler version with thrift -v and the python package version with pip show thrift.
Officially we only support versions 0.9.2 and 0.9.3. But feel free to try using 1.0.0 as well. The most important things is that the versions match.

@antoninbas Thank you for answering my questions again. It's very kind of you!

By checking the version of thrift and thrift python packet, I found the version didn't match: the Thrift compiler version is 1.0.0-dev but the version of Thrift python packet is 0.9.3. That's because I forgot having installed thrift 0.9.3 before, and I reinstalled it by cloning and following the P4Lang/Thrift.

Then I tried to fix the problem, I cd to the directory /usr/local/bin and renamed the executable file thrift:

mv thrift thrift1

and then installed the thrift 0.9.3

wget http://mirrors.hust.edu.cn/apache/thrift/0.9.3/thrift-0.9.3.tar.gz
tar -zxvf thrift-0.9.3.tar.gz
cd thrift-0.9.3
./configure
make
make install

Then the versions matched:

root@ubuntu:/home/wasdns/p4factory/targets/simple_router# thrift -version
Thrift version 0.9.3
root@ubuntu:/home/wasdns/p4factory/targets/simple_router# pip show thrift
Name: thrift
Version: 0.9.3
Summary: Python bindings for the Apache Thrift RPC system
Home-page: http://thrift.apache.org
Author: Thrift Developers
Author-email: dev@thrift.apache.org
License: Apache License 2.0
Location: /usr/local/lib/python2.7/dist-packages
Requires: 

cd to the simple_router directory and tried again, however, it still failed.

root@ubuntu:/home/wasdns/p4factory/targets/simple_router# ./run_add_demo_entries.bash 
ImportError: cannot import name TFrozenDict
ImportError: cannot import name TFrozenDict
ImportError: cannot import name TFrozenDict
ImportError: cannot import name TFrozenDict
ImportError: cannot import name TFrozenDict
ImportError: cannot import name TFrozenDict

Is it something wrong with the dependencies? I'm afraid of deleting the old version of Thrift because it brought me more questions before.

Could you show me how to do with it? I’m truly grateful for your help.

The thrift compiler takes a thrift IDL file as an input and produces -in our case- C++ source (for the server) and Python code (for the client). If you rollback the thrift compiler to a previous version, you still need to run the new compiler again otherwise the source files won't get re-generated and you will get the same exact error. In other words, you should probably do a make clean and build again.
Also the way you "removed" the existing thrift installation seems a little hacky to me. You moved the executable but are you sure that the right shared library are being picked up? You should probably remove everything installed by thrift under <prefix>/bin and <prefix>/lib and re-install. But then again maybe you won't need to do that.
Finally you seem to be using the first version of the behavioral-model (bmv1 or p4c-behavioral), which is pretty much deprecated at this stage. There is a similar mininet demo which uses the new behavioral-model (bmv2) and does not require p4factory: https://github.com/p4lang/behavioral-model#integrating-with-mininet.

@antoninbas

Thanks a lot. It's invaluable experience in my way to continue. The reason why I took the method that I mentioned above is because I think the libraries of Thrift 0.9.3 will take place of old ones when I make install it. With your guide, I learned a lot of important experiences of doing experiment myself. Thanks for your kindness.

Hi, @Wasdns

Did you solve this issue? I have a thrift compiler version of 0.11.0 and pip show thrift gives me 0.9.2. I am not sure how will I change the thrift compiler version to 0.9.2 or uninstall it.

@baganal this repo is no longer maintained (see README)