iamDecode / sklearn-pmml-model

A library to parse and convert PMML models into Scikit-learn estimators.
BSD 2-Clause "Simplified" License
76 stars 15 forks source link

ModuleNotFoundError: No module named 'sklearn_pmml_model.tree._tree' #10

Closed nf78 closed 5 years ago

nf78 commented 5 years ago

Hi,

I have installed all dependencies from requirements.txt in a virtualenv, but when trying to run the "minimal working example" code from the README.md, I get this error message:

Traceback (most recent call last): File "test.py", line 6, in from sklearn_pmml_model.ensemble import PMMLForestClassifier File "C:\GitKraken\errors-processor\sklearn_pmml_model\ensemble__init.py", line 6, in from .forest import PMMLForestClassifier File "C:\GitKraken\errors-processor\sklearn_pmml_model\ensemble\forest.py", line 3, in from sklearn_pmml_model.tree._tree import Tree, NODE_DTYPE File "C:\GitKraken\errors-processor\sklearn_pmml_model\tree\init__.py", line 6, in from .tree import PMMLTreeClassifier, construct_tree File "C:\GitKraken\errors-processor\sklearn_pmml_model\tree\tree.py", line 4, in from sklearn_pmml_model.tree._tree import Tree, NODE_DTYPE, TREE_LEAF, TREE_UNDEFINED ModuleNotFoundError: No module named 'sklearn_pmml_model.tree._tree'

iamDecode commented 5 years ago

Hey @nf78, thanks for your interest. I am going to guess you are running the repository code directly rather than installing the library through pip, am I correct?

If so, the Cython code for the decision tree is not yet compiled, and hence that module cannot be found. You can fix this by running this command python setup.py build_ext --inplace (you need to have Cython and a C compiler for this).

Let me know if this fixes the issue :) If so I will update the readme to include these steps

nf78 commented 5 years ago

Thanks for your quick reply!

I did installed the library using pip, however I need to mention I'm using Windows 10, in case this helps.

On the other hand, I have successfully tried this:

1.- downloaded the repository 2.- run the command: python setup.py build_ext --inplace 3.- copied the content to the folder C:\Users\\AppData\Local\Programs\Python\Python36\sklearn_pmml_model\tree

Unfortunately, now I get the error:

Exception: PMML model does not contain MiningModel.

Which seems to be an unsupported feature, that is included in the PMML file I'm trying to load?

iamDecode commented 5 years ago

I don't have access to a windows machine, so that will make testing a bit difficult. However, its clearly still an issue with the cython extensions not compiling. As far as I'm aware, pip should always run the setup, which should automatically build all required components.

Could you maybe share the output of pip install sklearn-pmml-model?

nf78 commented 5 years ago

Thanks for your quick reply!

I did installed the library using pip, however I need to mention I'm using Windows 10, in case this helps.

On the other hand, I have successfully tried this:

1.- downloaded the repository 2.- run the command: python setup.py build_ext --inplace 3.- copied the content to the folder C:\Users\AppData\Local\Programs\Python\Python36\sklearn_pmml_model\tree

nf78 commented 5 years ago

Here is the output of the pip install sklearn-pmml-model:

Collecting sklearn_pmml_model Requirement already satisfied: scipy in c:\users\appdata\local\programs\python\python36\lib\site-packages (from sklearn_pmml_model) (1.1.0) Requirement already satisfied: scikit-learn in c:\users\appdata\local\programs\python\python36\lib\site-packages (from sklearn_pmml_model) (0.20.3) Requirement already satisfied: pandas in c:\users\appdata\local\programs\python\python36\lib\site-packages (from sklearn_pmml_model) (0.23.4) Requirement already satisfied: cached-property in c:\users\appdata\local\programs\python\python36\lib\site-packages (from sklearn_pmml_model) (1.5.1) Requirement already satisfied: numpy in c:\users\appdata\local\programs\python\python36\lib\site-packages (from sklearn_pmml_model) (1.15.1) Requirement already satisfied: python-dateutil>=2.5.0 in c:\users\appdata\local\programs\python\python36\lib\site-packages (from pandas->sklearn_pmml_model) (2.6.1) Requirement already satisfied: pytz>=2011k in c:\users\appdata\local\programs\python\python36\lib\site-packages (from pandas->sklearn_pmml_model) (2018.5) Requirement already satisfied: six>=1.5 in c:\users\appdata\local\programs\python\python36\lib\site-packages (from python-dateutil>=2.5.0->pandas->sklearn_pmml_model) (1.11.0) Installing collected packages: sklearn-pmml-model Successfully installed sklearn-pmml-model-0.0.8

iamDecode commented 5 years ago

Ok I was able to reproduce the issue on a windows machine. Turns out that, for some reason, pip on Windows will download a copy of the uncompiled source into the directory you run pip install. Python will import from that uncompiled directory rather than the one that was properly built and put into you site-packages directory. When I remove this directory I was able to import and use the library just fine.

I will investigate why the copy is made, and try to prevent it in the next release.

iamDecode commented 5 years ago

@nf78 I just released a new version (0.0.9) that solves this issue for my Windows setup. Could you test if this resolves this issue for you too? The best way to test is to uninstall the library first and make sure any 'sklearn_pmml_model' directories are removed, then install the library through pip.

nf78 commented 5 years ago

@iamDecode thanks for the new release, I can confirm I have successfully tested the library, with a new pip install of the new version 0.0.9 (after full removal of any 'sklearn_pmml_model' directories and pip uninstall)

Aliciathefrog commented 4 years ago

@nf78 I just released a new version (0.0.9) that solves this issue for my Windows setup. Could you test if this resolves this issue for you too? The best way to test is to uninstall the library first and make sure any 'sklearn_pmml_model' directories are removed, then install the library through pip.

Hi. I have sklearn-pmml-model 0.0.14.1 on my pc and still get this error message: from sklearn_pmml_model.tree._tree import Tree, NODE_DTYPE, TREE_LEAF, TREE_UNDEFINED ModuleNotFoundError: No module named 'sklearn_pmml_model.tree._tree'

HELP!!!!!!

iamDecode commented 4 years ago

@Aliciathefrog sorry I wasn't able to get back to you any sooner. I've tried to run the library on Windows 10 (64bit) and was not able to reproduce the error you reported. Can you make sure that you indeed installed the latest version with pip, and have up to date version of sklearn, numpy and pandas? If that doesn't help, please share the exact versions of the libraries you are using (use the command: pip freeze) and some details about the OS (windows? 32 or 64 bit?), then I'll do my best to help you find the problem.