博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
P4实验问题 解决python模块导入
阅读量:4957 次
发布时间:2019-06-12

本文共 3648 字,大约阅读时间需要 12 分钟。

参考:

在执行./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, in 
from 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

转载于:https://www.cnblogs.com/qq952693358/p/6195041.html

你可能感兴趣的文章
算法总结
查看>>
后台自定义导航增加分类树N级下拉+利用JQUERY
查看>>
python导包的问题
查看>>
QTP 捕获对象模式切换
查看>>
poi操作Excel相关对象属性介绍及中级应用
查看>>
mysql数据类型
查看>>
1.MyBaits无代理全套增删改
查看>>
spring(二)
查看>>
Oracle的汉字转拼音首字母的函数
查看>>
排序算法
查看>>
GAN生成图像论文总结
查看>>
(转)让ubuntu9.10开机自动挂载NTFS分区
查看>>
presentModalViewController 的动画效果
查看>>
windows mobile 程序控件置顶
查看>>
ORA-02447: cannot defer a constraint that is not deferrable
查看>>
EditPlus注册码
查看>>
servlet+jsp+java实现Web应用
查看>>
乔坟往事-目录
查看>>
MAMP添加mysql的环境变量
查看>>
css3实现漂亮的倒影效果
查看>>