[Wekalist] ModuleNotFoundError: No module named 'javabridge._javabridge

166 views
Skip to first unread message

raul.para...@gmail.com

unread,
Nov 17, 2021, 8:32:17 AM11/17/21
to python-weka-wrapper
Hi,

I'm running weka wrapper in a clean machine. I've installed Jupyter Notebook and java jdk 11. These are the headers of my script:

'import os
import sys
sys.path
sys.path.append("/usr/lib/jvm/java-11-openjdk-amd64/bin/")
os.environ["JAVA_HOME"] = "/usr/lib/jvm/java-11-openjdk-amd64/"
!sudo -S apt-get update < pw
!sudo -S apt-get upgrade -y < pw

!apt-get install build-essential python3-dev
!apt-get install python3-pil python3-pygraphviz -y
!apt install openjdk-11-jdk
!apt-get install -y weka libsvm-java
!python3 -m venv pww3
!pip3 install javabridge --no-cache-dir
!pip3 install python-weka-wrapper3 --no-cache-dir
!pip3 install haversine

import weka.core.jvm as jvm
from weka.core.converters import Loader
from weka.classifiers import Classifier
from weka.timeseries import WekaForecaster
from weka.core.dataset import Instances
import haversine as hs
from haversine import Unit
import numpy as np
import pandas as pd
from javabridge import JWrapper
import weka.core.packages as packages
import timeit
from weka.filters import Filter
import math
from math import radians, cos, sin, asin, sqrt
from itertools import combinations
import geopy
import geopy.distance
import folium
from shapely import geometry, ops
import time'


However, I get this error:

'Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:3 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu focal-security InRelease
Reading package lists... Done
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
Requirement already satisfied: javabridge in ./lib/python3.8/site-packages (1.0.16)
Requirement already satisfied: numpy in ./lib/python3.8/site-packages (from javabridge) (1.21.4)
Requirement already satisfied: python-weka-wrapper3 in ./lib/python3.8/site-packages (0.2.3)
Requirement already satisfied: javabridge>=1.0.14 in ./lib/python3.8/site-packages (from python-weka-wrapper3) (1.0.16)
Requirement already satisfied: numpy in ./lib/python3.8/site-packages (from python-weka-wrapper3) (1.21.4)
Requirement already satisfied: haversine in ./lib/python3.8/site-packages (2.5.1)
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
/tmp/ipykernel_52084/1092990627.py in <module>
     36
     37
---> 38 import weka.core.jvm as jvm
     39 from weka.core.converters import Loader
     40 from weka.classifiers import Classifier

~/notebook/jupyterenv/lib/python3.8/site-packages/weka/core/jvm.py in <module>
     15 # Copyright (C) 2014-2020 Fracpete (pythonwekawrapper at gmail dot com)
     16
---> 17 import javabridge
     18 import os
     19 import glob

~/notebook/jupyterenv/lib/python3.8/site-packages/javabridge/__init__.py in <module>
     36
     37
---> 38 from .jutil import start_vm, kill_vm, vm, activate_awt, deactivate_awt
     39
     40 from .jutil import attach, detach, get_env

~/notebook/jupyterenv/lib/python3.8/site-packages/javabridge/jutil.py in <module>
    155     _find_jvm_mac()
    156
--> 157 import javabridge._javabridge as _javabridge
    158 __dead_event = threading.Event()
    159 __kill = [False]

ModuleNotFoundError: No module named 'javabridge._javabridge''


I've added the path of the jdk into JAVA_HOME and inserted at the end of bashrc

This code works correctly in Colab, however, in local it doesn't. I do know that Jupyter is not the appropriated environment, however, after re-running the kernel, it should work.

I don't know what is the problem. 

Peter Reutemann

unread,
Nov 17, 2021, 3:10:20 PM11/17/21
to python-weka-wrapper
[...]

> ModuleNotFoundError: No module named 'javabridge._javabridge''
>
> I've added the path of the jdk into JAVA_HOME and inserted at the end of bashrc
>
> This code works correctly in Colab, however, in local it doesn't. I do know that Jupyter is not the appropriated environment, however, after re-running the kernel, it should work.
>
> I don't know what is the problem.

Rather than trying a complex example, it is best to start small again.

Here are the steps on my Linux Mint machine to set up and run a
Jupyter Notebook:

1. set up a new virtual environment
virtualenv -p /usr/bin/python3 pww3
./pww3/bin/pip install numpy
./pww3/bin/pip install javabridge
./pww3/bin/pip install python-weka-wrapper3
./pww3/bin/pip install jupyter

2. Start up Jupyter notebook and create a new Python3 notebook
./pww3/bin/jupyter-notebook

3. Enter this code in a cell and run it (adapt the path to the nominal
dataset, of course):
import weka.core.jvm as jvm
from weka.core.converters import load_any_file
from weka.classifiers import Classifier
jvm.start()
data = load_any_file("/some/where/iris.arff")
data.class_is_last()
cls = Classifier(classname="weka.classifiers.trees.J48")
cls.build_classifier(data)
print(cls)
jvm.stop()

Which works fine on my machine.

The output of "./pww3/bin/pip freeze" is attached.

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, NZ
+64 (7) 858-5174 (office)
+64 (7) 577-5304 (home office)
http://www.cms.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
pip_freeze.txt
Reply all
Reply to author
Forward
0 new messages