pyflann icon indicating copy to clipboard operation
pyflann copied to clipboard

Python 3 support

Open mruegenberg opened this issue 8 years ago • 8 comments

Hi, I'm getting some errors when using Python 3 (3.4.3) (and installing from pip, pyflann 1.6.12).

  • I'm getting import errors due to relative imports. The solution is to replace various from foo import * with from .foo import *. See also here (This should also work in Python 2.)

    specifically:

    • bindings/init.py
    • the pyflann imports in index.py
    • both imports in init.py
    • io/init.py
    • the _dataset imports in io/dataset.py need to be relative as well, e.g from . import binary_dataset
  • after fixing these, I get invalid syntax in find_ctypes.py, line 151. The reason is that the except Exception, e syntax was replaced by except Exception as e:. In this case, it could just be except Exception:

  • same in io/dataset.py, line 61 and hdf5_dataset, line 34+67

  • in flann_ctypes, line 201, the exec call needs brackets

  • Python 3 no longer contains dict.iteritems and should be replaced by dict.items (in flann_ctypes, l.53 and 78)

(Not sure if this is the right place for these issues, I just followed the pip package to its source.)

Some additional errors which I'm not sure are the fault of Python 3:

  • I get an error about flann_parameters missing when __del is called. Apparently, they are deleted before the del call?

With these fixes, pyflann seems to work.

mruegenberg avatar Apr 09 '16 18:04 mruegenberg

Thank you so much for this! There's also another Exception in hdf5_dataset in line 85 that needs a syntax fix

dsurujon avatar Mar 31 '17 16:03 dsurujon

I run sudo 2to3 -w [pyflann directory in dist-packages] and worked.

jimkon avatar Dec 26 '17 18:12 jimkon

I tried following the instructions above, but I still got an error. ArgumentError: argument 9: <class 'TypeError'>: expected LP_FLANNParameters instance instead of LP_FLANNParameters In the end, jimkon's solution, however, worked fine. I had to switch to linux to run it obviously, but I can now run pyflann in windows after copying the modified files back over to my windows dist-packages folder.

It would be helpful to others I imagine if you could open up the Python3 branch of this so others could just install those files directly.

M00NSH0T avatar Mar 15 '18 14:03 M00NSH0T

@jimkon's solution works for me on OSX (10.14.4) with Python 3.7.4. I installed via pip, and then needed to specify an exception type for line 65 of binary_dataset.py:

63. else:
64.    if rows==-1 or cols==-1:
65.        #  raise "No .meta file present, you must specify dataset rows, cols asd dtype")
66.        raise ValueError("No .meta file present, you must specify dataset rows, cols asd dtype")

ghost avatar Aug 06 '19 09:08 ghost

I followed the instructions but I am getting this error

raise ImportError('Cannot load dynamic library. Did you compile FLANN?') ImportError: Cannot load dynamic library. Did you compile FLANN?

abdor95 avatar Dec 01 '22 10:12 abdor95

I followed the instructions but I am getting this error

raise ImportError('Cannot load dynamic library. Did you compile FLANN?') ImportError: Cannot load dynamic library. Did you compile FLANN?

@abdor95 I also got this error. After some debug I found the exact error for me: dlopen(.../pyflann/lib/python3.9/site-packages/pyflann/lib/darwin/libflann.dylib, 0x0006): tried: '.../pyflann/lib/darwin/libflann.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

I am running on a new M chip macbook. If you had the same issue and found a solution let me know. I am going to build my project on an old intel macbook for now and look at migrating later.

coamw2 avatar Jun 27 '23 14:06 coamw2

I followed the instructions but I am getting this error raise ImportError('Cannot load dynamic library. Did you compile FLANN?') ImportError: Cannot load dynamic library. Did you compile FLANN?

@abdor95 I also got this error. After some debug I found the exact error for me: dlopen(.../pyflann/lib/python3.9/site-packages/pyflann/lib/darwin/libflann.dylib, 0x0006): tried: '.../pyflann/lib/darwin/libflann.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

I am running on a new M chip macbook. If you had the same issue and found a solution let me know. I am going to build my project on an old intel macbook for now and look at migrating later.

Hi, Do you happen to find a solution for the M chip issue

in509 avatar Jul 30 '23 17:07 in509

This is old news, but I posted a solution to ^ here:

https://github.com/ddarmon/sidpy/#installation-on-arm-based-macs

ddarmon avatar Oct 11 '23 00:10 ddarmon