Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to import pyping for Python 3 but I am getting below error:

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'
>>>

Update 1

virt01@virt01:~/Python_Admin$ ls /usr/local/lib/python3.4/dist-packages/pyping/
core.py  __init__.py  __pycache__
like image 654
rɑːdʒɑ Avatar asked Feb 11 '16 04:02

rɑːdʒɑ


2 Answers

You can use ping3 library. But it requires root permission on your machine. This link shows the workaround (unprivileged ICMP sockets which allow to use ping without root).

like image 152
VeLKerr Avatar answered Nov 14 '22 07:11

VeLKerr


This is because of absolute imports being in effect (more precisely, the lack of implicit relative imports) for Python 3 and the fact that the pyping module was most likely only written for Python 2. Whereas in Python 2 you can do:

from core import *

In Python 3 (or if you have from __future__ import absolute_import in Python 2), you have to do:

from .core import *

or

from pyping.core import *

You have two options:

  1. ask the module author to make it compatible with Python 3
  2. fork it yourself and make it compatible with Python 3 (you can look into using 2to3 for this)
like image 26
univerio Avatar answered Nov 14 '22 09:11

univerio