简体   繁体   中英

Include a python package in a Java project

I have a Java Project in which i included a python script through the code:

    try {
        mProcess = Runtime.getRuntime().exec("python pythonScript.py");
    } catch (Exception e) {
        System.out.println(e.toString());
    }

Problem is the python code needs a python site package to run,

While running the python code alone in Pycharm it works correctly but intellij cant understand the code fully

these are the imports am trying to include in intellij

import ply.lex as lex

import ply.yacc as yacc

I did not understand completely your question, but maybe this can help you.

ArrayList<String> cmdLd = new ArrayList<String>();
cmdLd.add("python3");
cmdLd.add("pythonScript.py");
ProcessBuilder pb = new ProcessBuilder(cmdLd);
Process process = pb.start();
process.getOutputStream().close();
process.waitFor();

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