eclipse “模块”对象没有属性“PortScanner”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14913153/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
'module' object has no attribute 'PortScanner'
提问by Russ
I'm using Ubuntu 12.04 and installed python-nmap to create a script. If I use IDLE and type in the following, it runs fine:
我正在使用 Ubuntu 12.04 并安装了 python-nmap 来创建脚本。如果我使用 IDLE 并输入以下内容,它运行良好:
import nmap
nm = nmap.PortScanner()
nm.scan('127.0.0.1', '22-443')
However, if I perform this in Eclipse, I receive the following error:
但是,如果我在 Eclipse 中执行此操作,则会收到以下错误:
Traceback (most recent call last):
File "/home/russ/workspace/ViPyNmap/MyFiles/nmaptest.py", line 2, in <module>
nm = nmap.PortScanner()
AttributeError: 'module' object has no attribute 'PortScanner'
I've added the egg file and also the folder to the Eclipse path for the project, with no luck. I've also restarted Eclipse after doing so, with no luck. I apologize for my inexperience with both Eclipse and Python and appreciate the help.
我已经将egg 文件和文件夹添加到项目的Eclipse 路径中,但没有成功。这样做之后,我也重新启动了 Eclipse,但没有运气。我为我对 Eclipse 和 Python 的经验不足表示歉意,并感谢您的帮助。
回答by f_ficarola
回答by Wu_Being
1 analyzing
1 分析
If you see the source code nmap.py
at directory /usr/local/lib/python2.7/dist-packages/nmap/
, you will find that there is not class PortScanner.
如果你查看nmap.py
目录下的源代码/usr/local/lib/python2.7/dist-packages/nmap/
,你会发现没有PortScanner类。
2 solution
2 解决方案
2.1 method one
2.1 方法一
You should delete the directory .../nmap/
with contained files, and install the new the packages nmap
or bypython setup.py install
at new packages directory.
您应该删除.../nmap/
包含文件的目录,并安装新的软件包nmap
或通过python setup.py install
新的软件包目录安装。
2.2 method two
2.2 方法二
You also can copy the file nmap.py
at the new packages to your directory .../MyFiles/
with your py file nmaptest.py
, and run your command python nmaptest.py
.
您还可以将nmap.py
新包中的文件.../MyFiles/
与 py 文件一起复制到您的目录中 nmaptest.py
,然后运行您的命令python nmaptest.py
。
good luck for you !
祝你好运 !
回答by silpy
The reason why this is happening is because your module that you named nmap.py is now shadowing the intended requests module you are trying to use.
发生这种情况的原因是您命名为 nmap.py 的模块现在隐藏了您尝试使用的预期请求模块。
To avoid this, you should rename your module to something else to avoid these situations. Furthermore, chances are you will have generated a nmap.pyc file as well, local to where your nmap.py resides. Make sure you remove that as well after your rename, as the interpreter will still reference that file, re-producing the error.
为避免这种情况,您应该将模块重命名为其他名称以避免这些情况。此外,您可能还会生成一个 nmap.pyc 文件,位于您的 nmap.py 所在的本地。确保在重命名后也将其删除,因为解释器仍将引用该文件,从而重新产生错误。
Example of problem resolution:
问题解决示例:
renaming file to nmapscan.py, removing nmap.pyc and running again.
将文件重命名为 nmapscan.py,删除 nmap.pyc 并再次运行。
回答by whiteheart
Well above answers are working fine in python 2.7, but when we are working in python3 environment following will help to resolve it
以上答案在 python 2.7 中工作正常,但是当我们在 python3 环境中工作时,以下将有助于解决它
pip uninstall nmap pip uninstall python-nmap pip3 install python-nmap
pip卸载nmap pip卸载python-nmap pip3安装python-nmap