Author jeff.allen
Recipients jeff.allen, rkanumola
Date 2019-12-24.15:54:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Hi RK (and Happy Christmas). I had success with:

// Sample piece of code for issue 2818 (RK, JA)

import java.util.Properties;
import org.python.util.PythonInterpreter;
import org.python.core.PyString;

public class RunRedis {
    public static void main(String[] args) {
        try {

            Properties properties = new Properties();
            // You don't need these: Jython will find home (usually):
            //properties.setProperty("python.home", "../jython2.7.1/");
            //properties.setProperty("python.path", "../jython2.7.1/Lib");
            // *** This is what is stopping Jython finding site-packages/redis ***
            //properties.setProperty("", "false");
            PythonInterpreter.initialize(System.getProperties(), properties, new String[] {""});
            PythonInterpreter python = new PythonInterpreter();
            String script =
                "import sys\n" + 
                // You don't need this: Jython will find home (usually):
                //"sys.path.append(\"../jython2.7.1/Lib\")\n" + 
                "\n" + 
                // See what sys.path we get without forcing it:
                "print sys.path\n" + 
                "import redis\n" +
                "r = redis.Redis(host='localhost', port=6379)\n" + 
                "print repr(r)\n";
            //python.set("script", new PyString(script));

        } catch (Exception e) {

where "success" is defined as this output:

PS issue2818> javac -cp ".\inst\jython.jar"
PS issue2818> java -cp ".;.\inst\jython.jar" RunRedis
['...\\issue2818\\inst\\Lib', '__classpath__', '__pyclasspath__/', '...\\.local\\lib\\jython2.7\\site-packages', '...\\issue2818\\inst\\Lib\\site-packages']

If you suppress use site import, then site-packages is not on your path and redis will not be found. It's the same with "python -S" and:

PS issue2818> java -D"" -cp ".;.\inst\jython.jar" RunRedis
['...\\issue2818\\inst\\Lib', '__classpath__', '__pyclasspath__/']
Traceback (most recent call last):
  File "<string>", line 4, in <module>
ImportError: No module named redis
Date User Action Args
2019-12-24 15:54:18jeff.allensetmessageid: <>
2019-12-24 15:54:18jeff.allensetrecipients: + jeff.allen, rkanumola
2019-12-24 15:54:18jeff.allenlinkissue2818 messages
2019-12-24 15:54:18jeff.allencreate