How to fix 'ImportError: No module named ...' in Linux?

How to fix 'ImportError: No module named ...' in Linux?

我想尝试来自 http://csie.nqu.edu.tw/smallko/sdn/dijkstra_ryu.htm 的代码 但是当我尝试 运行 代码时,它不起作用。总是'ImportError: No module dijkstra_ryu.py'错误

我正在使用 Ubuntu 16.04.4 LTS,python 2.7.12 和 3.5.2,以及 ryu 4.23。

事情是这样的:

ray@raihanr:~/ryu/ryu/app$ ryu-manager dijkstra_ryu.py --observe-links
loading app dijkstra_ryu.py
Traceback (most recent call last):
File "/usr/local/bin/ryu-manager", line 9, in 
load_entry_point('ryu==4.23', 'console_scripts', 'ryu-manager')()
File "/usr/local/lib/python2.7/dist-packages/ryu/cmd/manager.py", line 98, in main
app_mgr.load_apps(app_lists)
File "/usr/local/lib/python2.7/dist-packages/ryu/base/app_manager.py", line 415, in load_apps
cls = self.load_app(app_cls_name)
File "/usr/local/lib/python2.7/dist-packages/ryu/base/app_manager.py", line 392, in load_app
mod = utils.import_module(name)
File "/usr/local/lib/python2.7/dist-packages/ryu/utils.py", line 104, in import_module
return importlib.import_module(modname)
File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
ImportError: No module named dijkstra_ryu.py

我也试过使用:

ryu/ryu/app$ ryu-manager --observe-links dijkstra_ryu.py

但一直显示相同的错误

可悲的是,我也试试这个:

:~$ryu-manager ryu/ryu/app/dijkstra_ryu.py --observe-links

然后出现新错误

ImportError: Import by filename is not supported.

我已经检查了每个模块,没有遗漏任何部分。

我找到了伙计们。问题在于间距规则。代码比较乱,需要把代码在定义里面的4倍间距做对,for,if等