参考:
在执行./run_demo.sh的过程中,遇到了python的模块问题:
root@ubuntu:/home/wasdns/tutorials/SIGCOMM_2015/source_routing# ./run_demo.sh ./run_demo.sh: line 31: /home/wasdns/tutorials/SIGCOMM_2015/source_routing/home/wasdns/p4c-bmv2/p4c_bm/__main__.py: No such file or directoryTraceback (most recent call last): File "topo.py", line 23, infrom p4_mininet import P4Switch, P4HostImportError: No module named p4_mininet
p4_mininet.py所在的文件夹:/home/wasdns/bmv2/mininet
root@ubuntu:/home/wasdns# cd bmv2/root@ubuntu:/home/wasdns/bmv2# lsaclocal.m4 config.status include Makefile.in test-driverautogen.sh config.sub install_deps.sh mininet testsautom4te.cache configure install-sh missing third_partycompile configure.ac libtool pdfixed thrift_srcconfig.guess CPPLINT.cfg LICENSE py-compile toolsconfig.h depcomp ltmain.sh README.md travisconfig.h.in docs m4 src VERSIONconfig.h.in~ Doxyfile Makefile stamp-h1config.log Doxymain.md Makefile.am targetsroot@ubuntu:/home/wasdns/bmv2# cd mininet/root@ubuntu:/home/wasdns/bmv2/mininet# ls1sw_demo.py simple_router.p4 stress_test_ipv4.py.inp4_mininet.py stress_test_commands.txtsimple_router.json stress_test_ipv4.py
于是要把这个路径加入python的系统路径中,过程如下:
1.先找到python的系统路径:
root@ubuntu:/home/wasdns# pythonPython 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import sys>>> sys.path['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/local/lib/python2.7/dist-packages/mininet-2.3.0d1-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/setuptools-32.1.0-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/pip-9.0.1-py2.7.egg', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']>>> exit()
找到/usr/local/lib/python2.7/dist-packages
这个路径。
cd /usr/local/lib/python2.7/dist-packages
2.增添.pth文件
root@ubuntu:/home/wasdns# cd /usr/local/lib/python2.7/dist-packagesroot@ubuntu:/usr/local/lib/python2.7/dist-packages# touch p4_mininet.pthroot@ubuntu:/usr/local/lib/python2.7/dist-packages# vim p4_mininet.pth/home/wasdns/bmv2/mininet
原因:
Python 在遍历已有的库文件目录(sys.path中指定)过程中,如果见到一个 .pth 文件,就会将该文件中所记录的路径加入到 sys.path 设置中,这样 .pth 文件说指明的库也就可以被 Python 运行环境找到。
3.查看路径,验证是否加入:
root@ubuntu:/usr/local/lib/python2.7/dist-packages# pythonPython 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import sys>>> sys.path['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/local/lib/python2.7/dist-packages/mininet-2.3.0d1-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/setuptools-32.1.0-py2.7.egg', '/usr/local/lib/python2.7/dist-packages/pip-9.0.1-py2.7.egg', '/home/wasdns/bmv2/mininet', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']
发现:'/home/wasdns/bmv2/mininet',解决问题。
2016/12/18