0

I got server which is starting process with python script and when it is running I got error:

    Traceback (most recent call last):
  File "save_boxes.py", line 2, in <module>
    import cv2
ImportError: No module named cv2

In fact I got opencv2 installed and script is working when I run it from terminal, have no ideas how to fix it, appreciate any advices, thank you!

The code Im running the script is:

 Process process;
            try {
                final char dm = (char) 34;
                ProcessBuilder pb = new ProcessBuilder("./runC.sh", "myArg1", "myArg2");
                Map<String, String> env = pb.environment();
                env.put("VAR1", "myValue");
                env.remove("OTHERVAR");
                env.put("VAR2", env.get("VAR1") + "suffix");
                pb.directory(new File("/home/user/IdeaProjects/MyServer/"));
                process = pb.start();
        
                int exitCode = process.waitFor();
                if (exitCode != 0) {
                    throw new IOException("Command exited with " + exitCode);
                }
            } catch (Exception e) {System.out.println ("error message: " + e.getLocalizedMessage());}

The script code:

#!/bin/bash

python my_script.py
3
  • 1
    Are you sure python command is pointing to python 3 or whatever version you are using? Normally, the command python points to python 2 so you might have to use python3 command to run python 3 interpreter instead. Commented Jun 20, 2020 at 16:10
  • when Im running from terminal "python" command is running ok, but I've tried change python to python3 in script and it worked, thanks a lot man, you may write an answer and I will accept it Commented Jun 20, 2020 at 16:13
  • can you show the output of "which python" run from terminal and run from script? When it is not the same output then you are running different versions. Commented Jun 20, 2020 at 16:20

1 Answer 1

2

Try to use python3. On most of the systems, python is a link to the Python 2 interpreter. :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.