P4实验问题 解决python模块导入
参考:Python导入自定义包或模块
在执行./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 directory
Traceback (most recent call last):
File "topo.py", line 23, in <module>
from p4_mininet import P4Switch, P4Host
ImportError: No module named p4_mininet
p4_mininet.py所在的文件夹:/home/wasdns/bmv2/mininet
root@ubuntu:/home/wasdns# cd bmv2/
root@ubuntu:/home/wasdns/bmv2# ls
aclocal.m4 config.status include Makefile.in test-driver
autogen.sh config.sub install_deps.sh mininet tests
autom4te.cache configure install-sh missing third_party
compile configure.ac libtool pdfixed thrift_src
config.guess CPPLINT.cfg LICENSE py-compile tools
config.h depcomp ltmain.sh README.md travis
config.h.in docs m4 src VERSION
config.h.in~ Doxyfile Makefile stamp-h1
config.log Doxymain.md Makefile.am targets
root@ubuntu:/home/wasdns/bmv2# cd mininet/
root@ubuntu:/home/wasdns/bmv2/mininet# ls
1sw_demo.py simple_router.p4 stress_test_ipv4.py.in
p4_mininet.py stress_test_commands.txt
simple_router.json stress_test_ipv4.py
于是要把这个路径加入python的系统路径中,过程如下:
1.先找到python的系统路径:
root@ubuntu:/home/wasdns# python
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "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-packages
root@ubuntu:/usr/local/lib/python2.7/dist-packages# touch p4_mininet.pth
root@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# python
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "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
P4实验问题 解决python模块导入的更多相关文章
- 一文解决python模块导入
python 模块导入 原理 查找是按照 sys.path 中的路径挨个扫描.若都不存在则提示error. sys.path路径第一个是当前运行脚本所在的目录,其后是PYTHONPATH(一般若步专门 ...
- python模块导入细节
python模块导入细节 官方手册:https://docs.python.org/3/tutorial/modules.html 可执行文件和模块 python源代码文件按照功能可以分为两种类型: ...
- 【转】python模块导入细节
[转]python模块导入细节 python模块导入细节 官方手册:https://docs.python.org/3/tutorial/modules.html 可执行文件和模块 python源代码 ...
- 详解Python模块导入方法
python常被昵称为胶水语言,它能很轻松的把用其他语言制作的各种模块(尤其是C/C++)轻松联结在一起.python包含子目录中的模块方法比较简单,关键是能够在sys.path里面找到通向模块文件的 ...
- python模块导入总结
python模块导入总结 模块导入方式 定义test.py模块 def print_func(): print("hello") import 语句 导入模块语法 import m ...
- python 模块导入import和import from区别
模块就是一个.py文件,在名字空间下导入模块导入import和import from,那么python 模块导入import和import from区别是什么呢 1,import 导入模块 impor ...
- python 模块导入
1. 模块导入: 要使用一个模块,我们必须首先导入该模块.Python使用import语句导入一个模块.例如,导入系统自带的模块 math: import math 你可以认为math就是一个指向已导 ...
- python模块导入-软件开发目录规范-01
模块 模块的基本概念 模块: # 一系列功能的结合体 模块的三种来源 """ 模块的三种来源 1.python解释器内置的模块(os.sys....) 2.第三方的别人写 ...
- python模块导入
官方手册:https://docs.python.org/3/tutorial/modules.html 可执行文件和模块 python源代码文件按照功能可以分为两种类型: 用于执行的可执行程序文件 ...
随机推荐
- [工作中的设计模式]桥接模式bridge
一.模式解析: 策略模式一节讲过,通过扩展持有者,使持有者形成抽象类,然后实现多个具体持有者,策略模式可以转化为桥接模式. 桥接模式定义为:将抽象部分与实现部分分离,使它们都可以独立的变化,在软件系统 ...
- [xsd学习]xsd基本要素
一.xsd常用数据格式 xs:string xs:decimal xs:integer xs:boolean xs:date xs:time 二.简易元素 <xs:element name=&q ...
- js兼容方法:事件添加|事件绑定|事件监听 addEvent
function addEvent(obj,sEvent,fn){ if(obj.attachEvent){ obj.attachEvent("on"+sEvent,fn); }e ...
- zoj 3469 Food Delivery 区间dp + 提前计算费用
Time Limit: 2 Seconds Memory Limit: 65536 KB When we are focusing on solving problems, we usual ...
- 同步、更新、下载Android Source & SDK from 国内镜像站
转自: 同步.更新.下载Android Source & SDK from 国内镜像站 Download the android source from china mirrors 以 ...
- iOS实现简书的账号识别方式(正则表达式)
通过简书iOS客户端登录,我们会看到请输入手机号或者邮箱登录,但是我们随机输入1234567的时候,便会弹出手机格式不正确,同样也会识别我们的邮箱格式,那么我们在项目中怎么实现这种判断呢? 0E471 ...
- MFC MSBDutyTable下载地址
点击此处跳转到下载地址 简明教程: 对于非制表人,只需要添加空余时间-新建,然后点星期和节数有课的那个按钮,勾选自己有课的周数.全部勾好后,生成空余时间表.然后查看自己的空余时间表,并导出,发给制表人 ...
- iOS UIImageView用代码添加点击事件
image.userInteractionEnabled = YES; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]ini ...
- BZOJ4367 : [IOI2014]holiday假期
设 $fl[i]$表示从$S$向左走,用了不超过$i$天且不回头的最大收益. $fr[i]$表示从$S$向右走,用了不超过$i$天且不回头的最大收益. $gl[i]$表示从$S$向左走,用了不超过$i ...
- Android 大位图加载
说明:没对图片进行缓存处理,只是使用软引用进行位图资源的释放,从而避免内存泄漏. 对位图进行解码显示: public Bitmap decodeBitmap(Resources resources, ...