pyroute2 icon indicating copy to clipboard operation
pyroute2 copied to clipboard

Import of IPRoute on Windows fails

Open iwanbolzern opened this issue 2 years ago • 7 comments

After updating to 0.6.10 (existing as well in 0.6.11 & 12) import of IPRoute fails on Windows:

    from pr2modules.iproute import IPRoute
..\..\..\.venv\lib\site-packages\pr2modules\iproute\__init__.py:132: in <module>
    from pr2modules import config
..\..\..\.venv\lib\site-packages\pr2modules\config\__init__.py:30: in <module>
    signal_stop_remote = signal.SIGUSR1
E   AttributeError: module 'signal' has no attribute 'SIGUSR1'

Thank you already in advance for looking into this!

iwanbolzern avatar Jun 14 '22 10:06 iwanbolzern

Confirmed. Will be fixed until Friday.

NB: pyroute2 is neither tested, nor used on Windows platform actively. There is still no CI workflow for pyroute2+Windows. If you are a Windows user and can contribute with code, testing or feasible usecases — you're welcome.

svinota avatar Jun 14 '22 15:06 svinota

@svinota I saw this bug is fixed in master 4b78de12, do you have a schedule when you're expecting to be released?

iwanbolzern avatar Nov 11 '22 16:11 iwanbolzern

Applied the patch 4b78de1251877b69c69416db0dadf92508906dc4 but still got an import error:

..\..\..\.venv\Lib\site-packages\pr2modules\__init__.py:10: in <module>
    import pyroute2  # noqa: F401
..\..\..\.venv\Lib\site-packages\pyroute2\__init__.py:77: in <module>
    loaded = entry_point.load()
..\..\..\.venv\Lib\site-packages\importlib_metadata\__init__.py:207: in load
    module = import_module(match.group('module'))
C:\Tools\Python3.11\Lib\importlib\__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
..\..\..\.venv\Lib\site-packages\pyroute2\netlink\diag\__init__.py:1: in <module>
    from socket import AF_INET, AF_INET6, AF_UNIX, IPPROTO_TCP, inet_ntop
E   ImportError: cannot import name 'AF_UNIX' from 'socket' (C:\Tools\Python3.11\Lib\socket.py)

iwanbolzern avatar Nov 14 '22 07:11 iwanbolzern

Can you please try the master branch? Thanks!

svinota avatar Nov 16 '22 11:11 svinota

Did try, now the problem is because of the ImportError suppress in __init__.py the IPRoute module does not get imported and hence it cannot find IPRoute in my part of the code. The reason why the IPRoute import fails is:

cannot import name 'MSG_DONTWAIT' from 'socket' (C:\\Tools\\Python3.9\\lib\\socket.py)

For better readability, I removed the

if not sys.platform.startswith('win'):
    raise
continue

Then we get the following error message:

test_ipr.py:3: in <module>
    from pyroute2 import IPRoute
..\..\pyroute2\__init__.py:78: in <module>
    loaded = entry_point.load()
C:\Tools\Python3.9\lib\importlib\metadata.py:77: in load
    module = import_module(match.group('module'))
C:\Tools\Python3.9\lib\importlib\__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
..\..\pyroute2\netlink\event\__init__.py:2: in <module>
    from pyroute2.netlink.generic import GenericNetlinkSocket
..\..\pyroute2\netlink\generic\__init__.py:23: in <module>
    from pyroute2.netlink.nlsocket import NetlinkSocket
..\..\pyroute2\netlink\nlsocket.py:95: in <module>
    from socket import (
E   ImportError: cannot import name 'MSG_DONTWAIT' from 'socket' (C:\Tools\Python3.9\lib\socket.py)

iwanbolzern avatar Nov 16 '22 19:11 iwanbolzern

Thanks, checking

svinota avatar Nov 16 '22 19:11 svinota

Hello, I have installed pyroute2 using pip (pip install pyroute2) and got this error:

import pyroute2
Traceback (most recent call last):
  File "C:\Users\Robin\AppData\Local\Programs\Python\Python310\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "C:\Users\Robin\AppData\Local\JetBrains\Toolbox\apps\PyCharm-C\ch-0\222.4345.23\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\Robin\projects\Shell\env\lib\site-packages\pyroute2\__init__.py", line 14, in <module>
    from pyroute2.config.version import __version__
  File "C:\Users\Robin\AppData\Local\JetBrains\Toolbox\apps\PyCharm-C\ch-0\222.4345.23\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "C:\Users\Robin\projects\Shell\env\lib\site-packages\pyroute2\config\__init__.py", line 30, in <module>
    signal_stop_remote = signal.SIGUSR1
AttributeError: module 'signal' has no attribute 'SIGUSR1'

And i know pyroute2 isn't tested on windows but i found it on an other open source project

thegame4craft avatar Jan 05 '23 12:01 thegame4craft