Issue2818

classification
Title: Support for Redis Module in PythonInterpreter
Type: Severity: normal
Components: Core, Library Versions: Jython 2.7
Milestone:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: rkanumola
Priority: Keywords:

Created on 2019-10-30.07:40:50 by rkanumola, last changed 2019-10-30.07:44:21 by rkanumola.

Messages
msg12728 (view) Author: RK (rkanumola) Date: 2019-10-30.07:40:50
We are using PythonInterpreter to interact of Redis script data which was invoked through Python script. And we are not able to import redis module and getting the folowing error. If the PythonInterpreter is not compatible with Redis module can you please check and give us this compatability .

Traceback (most recent call last):
  File "<string>", line 4, in <module>
ImportError: No module named redis

Sample piece of code which give the above error:
public static void main(String[] args) {
        try {
            Properties properties = new Properties();
            properties.setProperty("python.home", "/Users/ranumola/jython2.7.1/");
            properties.setProperty("python.path", "/Users/ranumola/jython2.7.1/Lib");
            properties.setProperty("python.import.site", "false");
            PythonInterpreter.initialize(System.getProperties(), properties, new String[] {""});
            PythonInterpreter python = new PythonInterpreter();
            String script = "# Python3 program to add two numbers \n" + "  \n" + "num1 = 15\n" + "num2 = 12\n" + "  \n" + "# Adding two nos \n"
                    + "sum = num1 + num2 \n" + "  \n" + "# printing values \n" + "print(\"Sum of {0} and {1} is {2}\" .format(num1, num2, sum)) ";
            String script1 = "import sys\n" + "sys.path.append(\"/Users/ranumola/jython2.7.1/Lib\")\n" + "\n" + "import redis\n"
                    + "r = redis.Redis(host='localhost', port=6379)\n" + "r.get('foo')";
            python.set("script", new PyString(script));
            python.exec(script);
            python.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
msg12730 (view) Author: RK (rkanumola) Date: 2019-10-30.07:44:21
Please ignore the previous sample. Take the following one for reference:
 try {
            Properties properties = new Properties();
            properties.setProperty("python.home", "../jython2.7.1/");
            properties.setProperty("python.path", "../jython2.7.1/Lib");
            properties.setProperty("python.import.site", "false");
            PythonInterpreter.initialize(System.getProperties(), properties, new String[] {""});
            PythonInterpreter python = new PythonInterpreter();
            String script = "import sys\n" + "sys.path.append(\"../jython2.7.1/Lib\")\n" + "\n" + "import redis\n"
                    + "r = redis.Redis(host='localhost', port=6379)\n" + "r.get('foo')";
            python.set("script", new PyString(script));
            python.exec(script);
            python.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
History
Date User Action Args
2019-10-30 07:44:21rkanumolasetmessages: + msg12730
2019-10-30 07:41:03rkanumolasettitle: Support for Redis Module for PythonInterpreter -> Support for Redis Module in PythonInterpreter
2019-10-30 07:40:50rkanumolacreate