简体   繁体   English

如何在Linux中修复'ImportError:没有名为...的模块'?

[英]How to fix 'ImportError: No module named …' in Linux?

I wanted to try codes from http://csie.nqu.edu.tw/smallko/sdn/dijkstra_ryu.htm but when I try to run the codes, it doesn't work. 我想尝试http://csie.nqu.edu.tw/smallko/sdn/dijkstra_ryu.htm中的代码,但是当我尝试运行代码时,它不起作用。 There always 'ImportError: No module dijkstra_ryu.py' error 始终存在'ImportError:No module dijkstra_ryu.py'错误

I am using Ubuntu 16.04.4 LTS, python 2.7.12 and 3.5.2, and ryu 4.23. 我使用的是Ubuntu 16.04.4 LTS,python 2.7.12和3.5.2,以及ryu 4.23。

Here's what happen: 这是发生的事情:

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

I also tried using: 我也试过用:

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

but it keeps showing the same error 但它一直显示相同的错误

Sadly, I also try this: 可悲的是,我也尝试这个:

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

then a new error shows up 然后出现一个新错误

ImportError: Import by filename is not supported.

I already checked every module and not missing any part. 我已经检查了每个模块,没有遗漏任何部分。

I FOUND IT GUYS. 我找到了他的家伙。 the problem is in the spacing rules. 问题在于间距规则。 the codes are messy, so we need to make it right for spacing that is 4 times when the codes are inside the definition, for, if, and etc. 代码很乱,所以当代码在定义中时,我们需要使间距为4倍,for,if等等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM