I write Python programs with eclipse IDE in Linux Backtrack5.
Scapy,Python 2.6 are available in Backtrack.Using auto-completion feature I’ve seen in all modules,But when i run the program, I see the following error:
from scapy.contrib.ospf import OSPF_Hdr
ImportError : No module named contrib.ospf
I’ve just started programming with Python, and many of the sources that I’ve encountered this problem.
The problem for me is very interesting, when coding everything is OK, but it is not running!
In addition to resolving this problem, I want to know why this problem occurs??And in general how to fix?
Maybe my question is a duplicate, but a complete solution and we need it, in which case it does not duplicate any other person who asks the question.
Your search path is wrong.
2 common causes are:
-the search path in your IDE is different from the search path in your shell. I don’t have experience with eclipse for python, but it happened to me with other IDEs.
So in bash you can write:
export PYTHONPATH=”$PYTHONPATH:/where/module/lives/”
to include the path.
How to include this in your bashprofile:
http://blog.streamitive.com/2011/12/01/export-pythonpathpythonpath/
You can include the path via python itself:
http://www.johnny-lin.com/cdat_tips/tips_pylang/path.html
When to include via bash and when to include via python itself:
include via python for controlled programms, when you know 100% your module will always be in the same location.
Else, you should set the path explicitly. Maybe in a startup shell script, in the crontab command, or wherever you are calling your python program.