urgent !!!weka classifier import invalid syntax error!!

357 views
Skip to first unread message

yuqi xiao

unread,
Oct 20, 2020, 5:43:38 PM10/20/20
to python-weka-wrapper
Hi, 

I'm trying to use weka in my jupyter notebook for python3 

when I try to execute: 
import weka.plot.classifiers as plcls
from weka.classifiers import Classifier, Evaluation

it comes with the error 
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/weka/core/converters.py", line 18, in <module> from weka.core.classes import OptionHandler File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/weka/core/classes.py", line 2085 except Exception, e: ^ SyntaxError: invalid syntax

I pip installed both python-weka-wrapper and python-weka-wrapper3. 

Could anyone please help me to solve this problem here? 

Peter Reutemann

unread,
Oct 20, 2020, 6:27:20 PM10/20/20
to python-weka-wrapper
"except Exception, e:" is Python 2 syntax, but you are using Python3.
You should never install both, just install python-weka-wrapper3.

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 577-5304
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/

yuqi xiao

unread,
Oct 20, 2020, 6:43:45 PM10/20/20
to python-weka-wrapper
Hi Peter,

Thanks for your reply. I just pip uninstall python-weka-wrapper and installed python-weka-wrapper3. 

Then try to execute the command: 
from weka.classifiers import Classifier, Evaluation
import weka.plot.classifiers as plcls

it says the following error: 
ModuleNotFoundError: No module named 'weka.classifiers'
ModuleNotFoundError: No module named 'weka.plot'

it seems like python can't find this module. 
Could you please help me with this? 

Peter Reutemann

unread,
Oct 20, 2020, 6:55:26 PM10/20/20
to python-weka-wrapper
> Thanks for your reply. I just pip uninstall python-weka-wrapper and installed python-weka-wrapper3.
>
> Then try to execute the command:
> from weka.classifiers import Classifier, Evaluation
> import weka.plot.classifiers as plcls
>
> it says the following error:
> ModuleNotFoundError: No module named 'weka.classifiers'
> ModuleNotFoundError: No module named 'weka.plot'
>
> it seems like python can't find this module.
> Could you please help me with this?

What were your steps to set up the virtual environment?

Here's what I use (on my Linux box):
- create virtual environment "venv" using Python 3.7:
virtualenv -p /usr/bin/python3.7 venv
- activate the environment:
. ./venv/bin/activate
- install required packages
pip install numpy
pip install javabridge
pip install python-weka-wrapper3

For testing, the following single line command will instantiate a J48
classifier and output its commandline:
python -c "import weka.core.jvm as jvm; from weka.classifiers import
Classifier; jvm.start(); cls =
Classifier(classname='weka.classifiers.trees.J48');
print(cls.to_commandline()); jvm.stop()"

yuqi xiao

unread,
Oct 20, 2020, 7:07:26 PM10/20/20
to python-we...@googlegroups.com
I use MacOS 2020
 installed python3.8 and add it to .bash_profile 
then 

brew install pkg-cong

brew install graphviz

pip install javabridge

pip install python-weka-wrapper


I tried your command and it's not working. I also tried to import weka.core.jvm. and the ModuleNotFoundError still showed here. 


but when I do $pip list the python-weka-wrapper3 not showed 

then i try to install the following error happens

image.png

--
You received this message because you are subscribed to a topic in the Google Groups "python-weka-wrapper" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python-weka-wrapper/t9JZqRKNrk8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python-weka-wra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python-weka-wrapper/CAHoQ12JVp6tzZ4Sb8TvihtVFecHjQA2a2Y1LO%2BoRZ%3D8EiYnmrw%40mail.gmail.com.

Peter Reutemann

unread,
Oct 20, 2020, 7:14:32 PM10/20/20
to python-weka-wrapper
Unfortunately, I don't have access to a Mac.

But it looks like the installation of javabridge fails and therefore python-weka-wrapper3 isn't installed either.

For javabridge to compile, you need Xcode installed (or at least, that was the case several years ago) and it required you to have the Java header files present as well (e.g., from an OpenJDK installation).

Cheers, Peter

You received this message because you are subscribed to the Google Groups "python-weka-wrapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-weka-wra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python-weka-wrapper/CAO%2Bb4sx1gDvgKfsJTW0w5RhVGrr%3DpaZiFLwVhaFvjrECQq8iLQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages