Re: ModuleNotFoundError: No module named 'javabridge._javabridge

Peter Reutemann <[email protected]>
Newsgroups gmane.comp.ai.weka
Message-ID <CAHoQ12+74imXky4SL7DmMxPk_-Rtdi0DCueBVFrrXoPgYjfKHw@mail.gmail.com>
> I'm running weka wrapper in a clean machine. I've installed Jupyter Notebook and trying to execute a script with these headers:
>
> 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 apt-mark unhold libcublas-dev && sudo apt-mark unhold libcublas10 && sudo apt-mark unhold libcudnn7 && sudo apt-mark unhold libcudnn7-dev && sudo apt-mark unhold libnccl-dev && sudo apt-mark unhold libnccl2
> !sudo -S apt-get update < pw
> !sudo -S apt-get upgrade -y < pw
> #!apt-get update
> #!apt-get upgrade -y
> #!sudo apt-get dist-upgrade
> #!sudo apt install update-manager-core
> #!sudo do-release-upgrade
>
> !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
> #!pip3 install weka
> !python3 -m venv pww3
> #!pip3 install javabridge
> !pip3 install javabridge --no-cache-dir
> !pip3 install python-weka-wrapper3 --no-cache-dir
> !pip3 install haversine
> #!pip3 install selenium
>
>
> #!pip install geopy
> #!pip install folium
> #!pipwin install shapely  # install through anaconda "conda install shapely"
> #!pipwin install shapely
> #!apt-get update
> #!apt-get remove
> #!apt-get upgrade
>
>
> 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
> #import io
> #from PIL import Image
>
> 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 didn't install Weka neither a Java environment, is that the problem?

python-weka-wrapper3 bundles Weka (at the time of writing 3.9.5).
You need a JDK installed, of course. As a Java process will host the
Weka objects and processes.

> This code works correctly in Colab, however, in local it doesn't

python-weka-wrapper3 is not well suited for Jupyter Notebook
environments (and therefore also Colab), as you will need to restart
the kernel whenever you install packages or stop the JVM.

BTW python-weka-wrapper3 has its own mailing list:
https://groups.google.com/g/python-weka-wrapper

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/
_______________________________________________
Wekalist mailing list -- [email protected]
Send posts to [email protected]
To unsubscribe send an email to [email protected]
To subscribe, unsubscribe, etc., visit https://list.waikato.ac.nz/postorius/lists/wekalist.list.waikato.ac.nz
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.