简体   繁体   中英

`java` command is not found from this Python process. Please ensure Java is installed and PATH is set for `java`

I don't know how to fix this error when I'm trying to run the following code:

df = wrapper.read_pdf(r'C:\End_to_End\1902\PN\Scenario1_AllCorrectMin\EPR.pdf')

Log:

FileNotFoundError                         Traceback (most recent call last)
~\AppData\Local\Continuum\anaconda3\lib\site-packages\tabula\wrapper.py in read_pdf(input_path, output_format, encoding, java_options, pandas_options, multiple_tables, **kwargs)
    107     try:
--> 108         output = subprocess.check_output(args)
    109 

~\AppData\Local\Continuum\anaconda3\lib\subprocess.py in check_output(timeout, *popenargs, **kwargs)
    335     return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
--> 336                **kwargs).stdout
    337 

~\AppData\Local\Continuum\anaconda3\lib\subprocess.py in run(input, timeout, check, *popenargs, **kwargs)
    402 
--> 403     with Popen(*popenargs, **kwargs) as process:
    404         try:

~\AppData\Local\Continuum\anaconda3\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors)
    708                                 errread, errwrite,
--> 709                                 restore_signals, start_new_session)
    710         except:

~\AppData\Local\Continuum\anaconda3\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
    996                                          os.fspath(cwd) if cwd is not None else None,
--> 997                                          startupinfo)
    998             finally:

FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

JavaNotFoundError                         Traceback (most recent call last)
<ipython-input-3-010e34a004ec> in <module>()
----> 1 df = wrapper.read_pdf(r'C:\End_to_End\1902\PN\Scenario1_AllCorrectMin\EPR.pdf')

~\AppData\Local\Continuum\anaconda3\lib\site-packages\tabula\wrapper.py in read_pdf(input_path, output_format, encoding, java_options, pandas_options, multiple_tables, **kwargs)
    109 
    110     except FileNotFoundError as e:
--> 111         raise JavaNotFoundError(JAVA_NOT_FOUND_ERROR)
    112 
    113     except subprocess.CalledProcessError as e:

JavaNotFoundError: `java` command is not found from this Python process. Please ensure Java is installed and PATH is set for `java`

I tried changing and creating the path in the environmental variables but did not work. Here is the screenshot:

系统属性

Does anyone know how to fix this? I have java version 8 (Checked through about java)

Under the System Variables click Path and then press the Edit... instead of New . Then in the next screen ( Edit environment variable for the Path variable) click New and add the address, eg C:\Program Files (x86)\Java\jre1.8.0_201\bin . Press OK and the Path variable will be appended/updated.

You will need to restart your environment (eg Chrome, Anaconda, etc) for the path to have effect.

You need to add Java to the path variable (look at this question in Java Help Center), not create a new one. Also, make sure you're properly referencing a file to read, looks like your log threw a FileNotFound exception.

I too faced the same issue on my work PC while trying to read table data from a PDF, using tabula . The following process helped me overcome this issue.

I also used amazon corretto , which is basically an openJDK. Free to use and install, maintained by Amazon.

Install it in C:\ drive.

Now, go to environment variables in system properties. Under system variables , double click Path and click New add the path like this C:\Users\20195579\amazon-corretto-11.0.12.7.1-windows-x64-jdk\jdk11.0.12_7

Also add new variable in system variables . Variable Name: JAVA_HOME variable value: C:\Users\20195579\amazon-corretto-11.0.12.7.1-windows-x64-jdk\jdk11.0.12_7 See below images. 在此处输入图像描述

Should look like this after adding: 在此处输入图像描述

Incase still facing issue, add Oracle javapath to Path in system variables . like this C:\Program Files (x86)\Common Files\Oracle\Java\javapath

checked both on work PC and personal PC, worked well.

Note that if you do not already have Java installed on your computer, this code will not work. i can confirm as i was previously not running Java and experiencing the issue, then when i downloaded Java and added it to PATH (as described in the solution above), it worked.

Summary:

  1. download & install java (copying the install location)
  2. add install location to the PATH variable in advanced system settings

I am also facing the same issue based on my experience, I am sharing here.

Step 1 - After download and completed installation of Java (copy a bin path location and add into environment variables) 垃圾箱位置

Step2 - Add Java PATH location in the environment variable. 在此处输入图像描述

Still you are getting same error restart your anaconda and Chrome or restart you pc.

Check below code in command prompt

java --version

Complete Java installation and environment variable path setting up guidance video - link .

在控制台中的 linux 分发类型上: >sudo apt install openjdk-8-jdk对我有用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM