gpt4 book ai didi

python - Weka python 包装器加载器

转载 作者:行者123 更新时间:2023-12-01 05:03:18 28 4
gpt4 key购买 nike

我已经在 Mc Os X 10.9.4 上安装了 weka python 包装器。我尝试运行示例代码:

import weka.core.jvm as jvm
jvm.start()

from weka.core.converters import Loader
l = Loader("weka.core.converters.ArffLoader")
d = l.load_file("X.arff")

d.set_class_index(d.num_attributes() - 1)
print(d)

我收到以下错误:

Failed to get class weka/core/converters/ArffLoader
Exception in thread "Thread-2" java.lang.NoClassDefFoundError: weka/core/converters/ArffLoader
Failed to instantiate weka.core.converters.ArffLoader/weka/core/converters/ArffLoader: weka/core/converters/ArffLoader
Caused by: java.lang.ClassNotFoundException: weka.core.converters.ArffLoader
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Traceback (most recent call last):
File "/Users/hani/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2883, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-5-d835d9d560d2>", line 2, in <module>
l = Loader("weka.core.converters.ArffLoader")
File "/Users/hani/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/python_weka_wrapper-0.1.10-py2.7.egg/weka/core/converters.py", line 40, in __init__
self.enforce_type(jobject, "weka.core.converters.Loader")
File "/Users/hani/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/python_weka_wrapper-0.1.10-py2.7.egg/weka/core/classes.py", line 113, in enforce_type
raise TypeError("Object does not implement or subclass " + intf_or_class + "!")
TypeError: Object does not implement or subclass weka.core.converters.Loader!

经过一番修补后,我意识到使用 os.chdir 将工作目录设置为 python-weka-wrapper 文件夹可以解决某些环境中的问题,但不是所有环境中的问题(例如,使用此技巧无法修复 pycharm)。有什么想法可以解决这个问题吗?

最佳答案

显然,使用 weka jar 文件的路径调用 jvm 可以解决问题:

jvm.start(class_path=['/some/where/python-weka-wrapper.jar', 
'/some/where/weka.jar'])

感谢 Peter Reutemann 的回复。

关于python - Weka python 包装器加载器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25586730/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com