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源代码文件按照功能可以分为两种类型: 用于执行的可执行程序文件 ...
随机推荐
- wpf,图片灰化处理
private BitmapSource ToGray(BitmapSource source) { FormatConvertedBitmap re = new FormatConvertedBit ...
- struts2总结二:第一个简单的struts2程序
到struts2官网上面下载struts2的jar包,然后解压. struts2的入门程序,实现简单的用户登录,struts2里面的helllo world.利用eclipse的开发工作如下: 1.首 ...
- Android自动化测试 - MonkeyRunner(三) 随手练习测试脚本
#coding=utf-8 import os import time #import MonkeyRunner three module from com.android.monkeyrunner ...
- 关于Ue4的深度模板
http://www.unrealchina.net/forum.php?mod=viewthread&tid=100234
- HTML5中lineCap端点样式遇到closePath()
定义和用法 lineCap 属性设置或返回线条末端线帽的样式. 注释:"round" 和 "square" 会使线条略微变长. 默认值: butt JavaSc ...
- node.js链接mysql
node.js连接数据库有很多种,比如:mongoose,oracle,mysql...,我自己玩就选了一个我很熟悉的轻量级的mysql数据库尝试了一把,感觉不错. 首先要把mysql客户端安装好,官 ...
- zookeeper 3.4.6启动流程粗略梳理
zookeeper 3.4.6 启动脚本里面 nohup "$JAVA" "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" " ...
- SQLite错误码
在SQLite中,执行SQL语句的sqlite3_exec()和sqlite3_prepare()两个核心方法的返回值都是一个整型数据,因此,当程序执行出现错误时,我们可以根据执行返回的整型数据来判断 ...
- php 从myslql里导出到excel
//导出excel 只wps可以打开public function takexcelAction(){ $name = $this->input->get_post('name'); $i ...
- Codeforces Round #352 (Div. 2) A Summer Camp
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard proble ...