UMEP-dev / UMEP-processing

GNU General Public License v3.0
7 stars 9 forks source link

URock can't find Java path #36

Closed jessikalonn closed 1 year ago

jessikalonn commented 1 year ago

Hi, I have problem finding my Java path when running URock and get this error:

Traceback (most recent call last): File "C:\Users/xlojes/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\processing_umep\functions\URock\H2gisConnection.py", line 327, in getJavaHome java_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\JavaSoft\Java Runtime Environment") FileNotFoundError: [WinError 2] Det går inte att hitta filen

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users/xlojes/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\processing_umep\processor\urock_processing_algorithm.py", line 323, in processAlgorithm javaDirDefault = getJavaDir(plugin_directory) File "C:\Users/xlojes/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\processing_umep\functions\URock\H2gisConnection.py", line 212, in getJavaDir javaPath = getJavaHome(os_type) File "C:\Users/xlojes/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\processing_umep\functions\URock\H2gisConnection.py", line 330, in getJavaHome exit() File "C:\OSGeo4W\apps\Python39\lib_sitebuiltins.py", line 26, in call raise SystemExit(code) SystemExit: None

Any idea what the problem is? I have following version: openjdk version "17.0.7" 2023-04-18 OpenJDK Runtime Environment Temurin-17.0.7+7 (build 17.0.7+7) OpenJDK 64-Bit Server VM Temurin-17.0.7+7 (build 17.0.7+7, mixed mode, sharing)

j3r3m1 commented 1 year ago

Hi Jessika, Thank you for submitting. I think this is solved with the last version of the code (pushed few seconds ago). Let me know if not we might chat to find the problem. Jérémy

biglimp commented 1 year ago

I downloaded latest version and have problems in the studentlabs:

Traceback (most recent call last):
File "C:\Users/xlinfr/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\UMEP-processing-main\functions\URock\H2gisConnection.py", line 349, in getJavaHome
java_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\JavaSoft\Java Runtime Environment")
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users/xlinfr/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\UMEP-processing-main\processor\urock_processing_algorithm.py", line 323, in processAlgorithm
javaDirDefault = getJavaDir(plugin_directory)
File "C:\Users/xlinfr/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\UMEP-processing-main\functions\URock\H2gisConnection.py", line 234, in getJavaDir
javaPath = getJavaHome(os_type)
File "C:\Users/xlinfr/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\UMEP-processing-main\functions\URock\H2gisConnection.py", line 355, in getJavaHome
exit()
File "C:\OSGeo4W\apps\Python39\lib\_sitebuiltins.py", line 26, in __call__
raise SystemExit(code)
SystemExit: None

Execution failed after 0.04 seconds

The PC have some kind of java:

U:\>java -version
openjdk version "11.0.19" 2023-04-18 LTS
OpenJDK Runtime Environment (build 11.0.19+7-LTS)
OpenJDK 64-Bit Server VM (build 11.0.19+7-LTS, mixed mode)

@j3r3m1 , how do I locate java? It is not in program files...

biglimp commented 1 year ago

Ok, I found it C:\Program Files\OpenJDK\jdk-11.0.19-full\

j3r3m1 commented 1 year ago

Yes same problem as for @jessikalonn. My fix is not sufficient, I should encapsulate it in a try except condition. I try a correction right now

j3r3m1 commented 1 year ago

If the new version does not work, can you tell me what is the result of


import winreg
java_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\JavaSoft\Java Development Kit")
current_version, _ = winreg.QueryValueEx(java_key, "CurrentVersion")
java_version_key = winreg.OpenKey(java_key, current_version)
javaPath, _ = winreg.QueryValueEx(java_version_key, "JavaHome")
print(javaPath)
biglimp commented 1 year ago

Now its running...

image

Plakias commented 5 months ago

Hey! I am facing the same issue:

Traceback (most recent call last): File "C:\Users/plakias/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\UMEP-processing-main\functions\URock\H2gisConnection.py", line 349, in getJavaHome java_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\JavaSoft\Java Runtime Environment") FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users/plakias/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\UMEP-processing-main\functions\URock\H2gisConnection.py", line 353, in getJavaHome java_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\JavaSoft\Java Development Kit") FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "C:\Users/plakias/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\UMEP-processing-main\processor\urock_processing_algorithm.py", line 324, in processAlgorithm javaDirDefault = getJavaDir(plugin_directory) File "C:\Users/plakias/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\UMEP-processing-main\functions\URock\H2gisConnection.py", line 234, in getJavaDir javaPath = getJavaHome(os_type) File "C:\Users/plakias/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\UMEP-processing-main\functions\URock\H2gisConnection.py", line 356, in getJavaHome exit() File "C:\PROGRA~1\QGIS32~1.13\apps\Python39\lib_sitebuiltins.py", line 26, in call raise SystemExit(code) SystemExit: None

Execution failed after 0.03 seconds

I run the latest UMEP for processing vesion. (2.0.26? changelog says 2.0.28)

java -version

java version "22.0.1" 2024-04-16 Java(TM) SE Runtime Environment (build 22.0.1+8-16) Java HotSpot(TM) 64-Bit Server VM (build 22.0.1+8-16, mixed mode, sharing)

However I cant locate the registry path:

import winreg java_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\JavaSoft\Java Development Kit") Traceback (most recent call last): File "", line 1, in FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden currentversion, = winreg.QueryValueEx(java_key, "CurrentVersion") Traceback (most recent call last): File "", line 1, in NameError: name 'java_key' is not defined java_version_key = winreg.OpenKey(java_key, current_version) Traceback (most recent call last): File "", line 1, in NameError: name 'javakey' is not defined javaPath, = winreg.QueryValueEx(java_version_key, "JavaHome") Traceback (most recent call last): File "", line 1, in NameError: name 'java_version_key' is not defined print(javaPath) Traceback (most recent call last): File "", line 1, in NameError: name 'javaPath' is not defined

I manually located the registry path here: "Computer\HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\JDK\22.0.1\MSI"

Any ideas how to fix this?

j3r3m1 commented 5 months ago

Thanks for reporting. Can you try and report what is the output of the following code in the QGIS Python console ?


import winreg
java_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\JavaSoft\JDK")
current_version, _ = winreg.QueryValueEx(java_key, "CurrentVersion")
java_version_key = winreg.OpenKey(java_key, current_version)
javaPath, _ = winreg.QueryValueEx(java_version_key, "JavaHome")
print(javaPath)