为 Python 3 使用 pyping 时没有名为 'core' 的模块

No module named 'core' when using pyping for Python 3

我正在尝试为 Python 3 导入 pyping,但出现以下错误:

virt01@virt01:~/Python_Admin$ python3
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyping
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/dist-packages/pyping/__init__.py", line 3, in <module>
    from core import *
ImportError: No module named 'core'
>>>

更新 1

virt01@virt01:~/Python_Admin$ ls /usr/local/lib/python3.4/dist-packages/pyping/
core.py  __init__.py  __pycache__

这是因为绝对导入对 Python 3 有效(更准确地说,缺少隐式相对导入),而且 pyping 模块很可能只为 Python 2. 而在 Python 2 中你可以这样做:

from core import *

在 Python 3 中(或者如果你在 Python 2 中有 from __future__ import absolute_import),你必须做:

from .core import *

from pyping.core import *

你有两个选择:

  1. 请求模块作者使其兼容Python 3
  2. 自己 fork 并使其与 Python 3 兼容(你可以考虑使用 2to3

您可以使用 ping3 library. But it requires root permission on your machine. This link 显示解决方法(允许在没有 root 的情况下使用 ping 的非特权 ICMP 套接字)。