storpipfugl / pykdtree

Fast kd-tree implementation in Python
GNU Lesser General Public License v3.0
215 stars 47 forks source link

ModuleNotFoundError: No module named 'pykdtree.kdtree' #69

Closed Mechazo11 closed 2 years ago

Mechazo11 commented 2 years ago

Hi,

I have followed the installation instruction and can get pykdtree to compile without fault (though some warning messages pop up)

Before integrating into my code, I tried the following

python3
from pykdtree.kdtree import KDTree

But I am getting this error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pykdtree.kdtree'

Any help in resolving this matter will be highly appreciated. I am working on a Visual SLAM project and am curious to see how your algorithm will perform when querying through 500 - 1000 tracked keypoints per image frame.

Here is the log I get after running python3 setup.py install (I have both versions of python hence need the python3 keyword).

Log from console after installation is complete

running install
/usr/local/lib/python3.8/dist-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
/usr/local/lib/python3.8/dist-packages/setuptools/command/easy_install.py:144: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
/usr/local/lib/python3.8/dist-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 0.1.36ubuntu1 is an invalid version and will not be supported in a future release
  warnings.warn(
/usr/local/lib/python3.8/dist-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 0.23ubuntu1 is an invalid version and will not be supported in a future release
  warnings.warn(
/usr/local/lib/python3.8/dist-packages/pkg_resources/__init__.py:123: PkgResourcesDeprecationWarning: 1.13.1-unknown is an invalid version and will not be supported in a future release
  warnings.warn(
running bdist_egg
running egg_info
writing pykdtree.egg-info/PKG-INFO
writing dependency_links to pykdtree.egg-info/dependency_links.txt
writing requirements to pykdtree.egg-info/requires.txt
writing top-level names to pykdtree.egg-info/top_level.txt
reading manifest file 'pykdtree.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
adding license file 'LICENSE.txt'
writing manifest file 'pykdtree.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
running build_ext
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/pykdtree
copying build/lib.linux-x86_64-cpython-38/pykdtree/render_template.py -> build/bdist.linux-x86_64/egg/pykdtree
copying build/lib.linux-x86_64-cpython-38/pykdtree/__init__.py -> build/bdist.linux-x86_64/egg/pykdtree
copying build/lib.linux-x86_64-cpython-38/pykdtree/kdtree.cpython-38-x86_64-linux-gnu.so -> build/bdist.linux-x86_64/egg/pykdtree
copying build/lib.linux-x86_64-cpython-38/pykdtree/test_tree.py -> build/bdist.linux-x86_64/egg/pykdtree
byte-compiling build/bdist.linux-x86_64/egg/pykdtree/render_template.py to render_template.cpython-38.pyc
byte-compiling build/bdist.linux-x86_64/egg/pykdtree/__init__.py to __init__.cpython-38.pyc
byte-compiling build/bdist.linux-x86_64/egg/pykdtree/test_tree.py to test_tree.cpython-38.pyc
creating stub loader for pykdtree/kdtree.cpython-38-x86_64-linux-gnu.so
byte-compiling build/bdist.linux-x86_64/egg/pykdtree/kdtree.py to kdtree.cpython-38.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying pykdtree.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pykdtree.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pykdtree.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pykdtree.egg-info/not-zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pykdtree.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying pykdtree.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
creating 'dist/pykdtree-1.3.5-py3.8-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing pykdtree-1.3.5-py3.8-linux-x86_64.egg
removing '/usr/lib/python3.8/site-packages/pykdtree-1.3.5-py3.8-linux-x86_64.egg' (and everything under it)
creating /usr/lib/python3.8/site-packages/pykdtree-1.3.5-py3.8-linux-x86_64.egg
Extracting pykdtree-1.3.5-py3.8-linux-x86_64.egg to /usr/lib/python3.8/site-packages
pykdtree 1.3.5 is already the active version in easy-install.pth

Installed /usr/lib/python3.8/site-packages/pykdtree-1.3.5-py3.8-linux-x86_64.egg
Processing dependencies for pykdtree==1.3.5
Searching for numpy==1.22.2
Best match: numpy 1.22.2
Adding numpy 1.22.2 to easy-install.pth file
Installing f2py script to /usr/bin
Installing f2py3 script to /usr/bin
Installing f2py3.8 script to /usr/bin

Using /usr/local/lib/python3.8/dist-packages
Finished processing dependencies for pykdtree==1.3.5
djhoese commented 2 years ago

When you run python setup.py install you are building an installable package and then those files are copied to your environments file install location (site-packages). This is usually fine, except in your case I'm guessing you probably also want to modify the code and see how it behaves? If not, is there a reason you are installing from source rather than PyPI?

When you run python and try to import something, Python checks your current working directory first. My guess is you are still in the pykdtree root directory (where setup.py is). In this case, python is trying to import the unbuilt/uncompiled version from the pykdtree source and is not finding the compiled modules. These modules are in your site-packages where you installed the package. If this is all accurate, you have two choices:

  1. Move to a different directory that doesn't have the pykdtree source in it.
  2. Re-install the package with pip install -e .. This will install pykdtree in an "editable" state where changes to the python files are automatically captured and the cython modules are compiled in place. However, if you plan on modifying the cython code then there are extra steps to perform: you have to regenerate the cython code from the mako template and then rerun pip install -e . --no-deps to rebuild the cython modules. There are some simplifications that can be made, but this should work.
Mechazo11 commented 2 years ago

@djhoese Thank you very much for the clue to PyPI method. I can import the module without issues now.

No, I do not plan on making any changes, just wanted to try pykdtree as an alternative to cKDTree from Scipy. I was just following the installation instruction in the README file.

I think it may be beneficial to add pip3 install pykdtree in the README file for those who just wants to try out the package.

Thanks again for the prompt response.

With best, @Mechazo11

djhoese commented 2 years ago

You are right. Those instructions need to be rewritten. Thanks.