jgrss / mpglue

A Python library for image and vector processing
MIT License
8 stars 3 forks source link

No module named 'mpglue.classification._moving_window' #6

Open takaakimasaki opened 5 years ago

takaakimasaki commented 5 years ago

I get an error message saying "No module named 'mpglue.classification._moving_window'" when I run "import mpglue import moving_window." I am running it on my Mac (MacOS High Sierra). Any advice you could give on solving this issue would be appreciated.

jgrss commented 5 years ago

How did you install MpGlue? Did you build from source (below)?

python setup.py build && python setup.py install
takaakimasaki commented 5 years ago

Yes I did install mpglue. But it still returns an error: This is the entire error message I got:

import mpglue as gl /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pysal/init.py:65: VisibleDeprecationWarning: PySAL's API will be changed on 2018-12-31. The last release made with this API is version 1.14.4. A preview of the next API version is provided in the pysal 2.0 prelease candidate. The API changes and a guide on how to change imports is provided at https://pysal.org/about ), VisibleDeprecationWarning) Traceback (most recent call last): File "", line 1, in File "/Users/takaakimasaki/Dropbox/programming/python/mpglue/mpglue/init.py", line 3, in from .classification.classification import classification, classification_r File "/Users/takaakimasaki/Dropbox/programming/python/mpglue/mpglue/classification/classification.py", line 26, in from ._moving_window import moving_window ModuleNotFoundError: No module named 'mpglue.classification._moving_window'

jgrss commented 5 years ago

The _moving_window module is a Cython module, so let's see if it compiled properly.

  1. Do you see _moving_window.so under /Users/takaakimasaki/Dropbox/programming/python/mpglue/mpglue/classification?
  2. If no to (1), do you have Cython installed?
  3. If yes to (2), do you see a list of .pyx files when running python setup.py build && python setup.py install?
takaakimasaki commented 5 years ago

Yes, I do see all those files. But still says "ModuleNotFoundError: No module named 'mpglue.classification._moving_window'"... Not sure what's driving this error.

jgrss commented 5 years ago

Can you uninstall mpglue, rebuild and install and post the tail of the traceback?

takaakimasaki commented 5 years ago

Thank you so much for looking into this. I actually tried to do it on my Windows PC and still got the same error message... Any help you can provide on this would be much appreciated!

Traceback (most recent call last): File "", line 1, in File "C:\Users\acer\Dropbox\programming\Python\mpglue\mpglue__init__.py", line 3, in from .classification.classification import classification, classification_r File "C:\Users\acer\Dropbox\programming\Python\mpglue\mpglue\classification\classification.py", line 26, in from ._moving_window import moving_window ModuleNotFoundError: No module named 'mpglue.classification._moving_window'

vdeluca commented 5 years ago

Hi, I've the same error when I import mpglue from python shell This is my complete trace:

1) Build and Install https://paste.ofcode.org/r5DYguwXtxU8kRffza3ZaL

2) pip install https://paste.ofcode.org/YmXu7xVdcfms7MJHF79GYx

3) import https://paste.ofcode.org/EyvF7GA9g8FTz3f7hLx2VZ

Thanks, so much!

vdeluca commented 5 years ago

Also, this is the classification's dir content

https://paste.ofcode.org/ZnbEvHTZbq8YtY7F25VdG

vdeluca commented 5 years ago

Solved! Was my fault unzip mpglue folder at the same point to access the python shell,

import mpglue the .so files were compiled into virtual envoiroment path

Also, I must to install 2 pypi extra, Fiona and shapely

jgrss commented 5 years ago

@takaakimasaki where are you importing mpglue from on your terminal? See below if you are attempting to import from within your mpglue Git directory.

Looking at the traceback of @vdeluca I can see that the installation was clean. However, in the (3. import) test you were inside the mpglue Git directory that you pulled. If you pip install then the package is installed into your environment /site-packages directory. The mpglue Git directory doesn't have any .pyx extensions compiled. Therefore, if you try to import mpglue from within the Git directory, Python will first attempt to import the relative package, when the correct installed package is in your /site-packages.

You can check where you environment /site-packages directory is located by importing another package, like:

>>> import numpy as np
>>> print(np.__file__)

To test the installation of mpglue, cd somewhere like your home directory so that Python cannot see the Git directory.

jgrss commented 5 years ago

Here is an example of what I was referring to in the previous comment.

> git clone https://github.com/jgrss/mpglue/
> cd mpglue/
# activate a virtual environment if you have one
> python setup.py build && pip install --upgrade --user .
> cd ~
> python -c "import mpglue"

If you do not cd outside of the Git directory after building then it won't import the correct package. If, however, you want to use the Git directory as the import, you would need to do something like:

> git clone https://github.com/jgrss/mpglue/
> cd mpglue/
> # activate a virtual environment if you have one
> python setup.py build_ext --inplace
# add this Git directory path to PYTHONPATH
jgrss commented 5 years ago

Also, this is the classification's dir content

https://paste.ofcode.org/ZnbEvHTZbq8YtY7F25VdG

@vdeluca The above link should be related to the same issue. The import fails because you are missing the compiled files (.so files) inside the Git directory. If you check the mpglue /site-packages directory after installation, you should see the .so files.