mjschultz / py-radix

Python radix tree implementation for IPv4 and IPv6 prefix matching.
Other
121 stars 37 forks source link

Cannot get working on Windows 7, v2.7.14 #33

Open sockduct opened 6 years ago

sockduct commented 6 years ago

Am I doing something wrong? Please let me know if you need additional details or would like me to try something.

sockduct commented 6 years ago

I cloned the repo and set it up without C extensions. Using the same setup as above I get this:

>>> import radix
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build\bdist.win32\egg\radix\__init__.py", line 4, in <module>
  File "build\bdist.win32\egg\radix\radix.py", line 1, in <module>
ImportError: cannot import name inet_pton

The fix for this is to pip install win_inet_pton (inet_pton isn't available in the stdlib socket on Windows for 2.x):

>>> import socket
>>> socket.inet_pton
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'inet_pton'

Once I do this, I can get it to work:

>>> import win_inet_pton
>>> import radix
>>> rtree = radix.Radix()
>>> rnode = rtree.add("10.0.0.0/8")

I thought this might be fixed in Python 3.4+ as described in issue 7171. If I check in Python 3.6, I can see that inet_pton is now included in the stdlib socket:

>>> import socket
>>> socket.inet_pton
<built-in function inet_pton>

However, I still get the same error in 3.6.3 on Windows 7:

> python
Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 17:26:49) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import radix
>>> rtree = radix.Radix()
>>> rnode = rtree.add("10.0.0.0/8")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Either the application has not called WSAStartup, or WSAStartup failed.
>>>

But, if I clone the repo and build this without C extensions it does work correctly in 3.6 on Windows. So, there must be some difference in the way inet_pton works on Windows vs. POSIX systems.

Note - as with Python 2.7, installing the package win_inet_pton and importing it before py-radix fixes the issue (if using C extensions).

--Jim

mjschultz commented 6 years ago

Thanks for the information. I don't have a windows platform to test this on so I can't be much help on that front.

I'd certainly prefer to not have an external dependency on win_inet_pton as part of this, so perhaps an addition in the README to that effect for Windows platforms.

If you feel compelled to make a PR to fix support for Windows I would gladly accept it. (If it has a regression test runner system like appveyor.yml which I've not gotten to work that would be better.)

ghost commented 6 years ago

I'd certainly prefer to not have an external dependency on win_inet_pton as part of this, so perhaps an addition in the README to that effect for Windows platforms.

Also, if that is only needed for Windows? requirements in setup.py can be platform-dependent.

sockduct commented 6 years ago

@mjschultz I'm not a C programmer, so I can't help with a solution to make the C extension Windows compatible without using win_inet_pton. However, if you would be willing to accept a PR to setup.py (per @wagner-certat's suggestion) and the README.rst I might be willing to take a stab at that. Please let me know.