Re: Servlet ImportError: Cannot import site module and its dependencies: No module named site

Alan Kennedy <[email protected]> Sat, 27 Aug 2016 13:47:00 +0100
Newsgroups gmane.comp.lang.jython.user
Message-ID <CAMte6hmuT_G4jSLeLyVV6ETQ9ry++FW3Z2cdfYFWDUbKqNedrg@mail.gmail.com>
Hi David.

The modjy documentation has a fair amount of detail about running jython
inside servlet containers. Although the docs are for modjy, the
configuration details described are also generally applicable to running
jython in servlet containers.

These two pages should contain relevant information.

http://opensource.xhaus.com/projects/modjy/wiki/ModjyDeployment
http://opensource.xhaus.com/projects/modjy/wiki/ModjyTroubleShooting

The relevant java code that controls all of this is here

https://hg.python.org/jython/file/tip/src/com/xhaus/modjy/ModjyJServlet.java

In particular, it looks like you should be looking at the jython registry,
how it is located and what values it contains.

https://wiki.python.org/jython/UserGuide#finding-the-registry-file
http://www.jython.org/jythonbook/en/1.0/appendixA.html

Lastly, is there a reason why you don't want to use modjy? It is custom
designed for running jython application inside servlet containers,
specifically WSGI applications.

Regards,

Alan.


On Tue, Aug 23, 2016 at 11:21 PM, David Charles <[email protected]>
wrote:

> I just created my first servlet in Jython2.7.0 running on
> Apache2/Tomcat6.  When I tried to access my servlet with my browser, I got
> the following error message:
>
> HTTP Status 500 - Servlet.init() for servlet PyServlet threw exception
> ------------------------------
>
> *type* Exception report
>
> *message* *Servlet.init() for servlet PyServlet threw exception*
>
> *description* *The server encountered an internal error that prevented it
> from fulfilling this request.*
>
> *exception*
>
> javax.servlet.ServletException: Servlet.init() for servlet PyServlet threw exception
> 	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
> 	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
> 	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
> 	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
> 	org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
> 	java.lang.Thread.run(Thread.java:745)
>
> *root cause*
>
> ImportError: Cannot import site module and its dependencies: No module named site
> Determine if the following attributes are correct:
>   * sys.path: ['/var/lib/tomcat6/webapps/jythonsample/WEB-INF/lib/Lib', '__classpath__', '__pyclasspath__/']
>     This attribute might be including the wrong directories, such as from CPython
>   * sys.prefix: /var/lib/tomcat6/webapps/jythonsample/WEB-INF/lib
>     This attribute is set by the system property python.home, although it can
>     be often automatically determined by the location of the Jython jar file
>
> You can use the -S option or python.import.site=false to not import the site module
>
> 	org.python.core.Py.ImportError(Py.java:328)
> 	org.python.core.Py.importSiteIfSelected(Py.java:1563)
> 	org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:116)
> 	org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:94)
> 	org.python.util.PyServlet.createInterpreter(PyServlet.java:124)
> 	org.python.util.PyServlet.reset(PyServlet.java:170)
> 	org.python.util.PyServlet.init(PyServlet.java:90)
> 	javax.servlet.GenericServlet.init(GenericServlet.java:212)
> 	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
> 	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
> 	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
> 	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
> 	org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
> 	java.lang.Thread.run(Thread.java:745)
>
> *note* *The full stack trace of the root cause is available in the Apache
> Tomcat/6.0.39 logs.*
> ------------------------------
> Apache Tomcat/6.0.39This is a web application, so I am not using the
> command-line interface (so I cannot pass -S), nor am I starting the
> interpreter from some Java code (so I cannot set property
> python.import.site).
>
> As a quick experiment, I copied the my $JYTHON_HOME/Lib directory into
> jythonsample/WEB-INF/libs and this made the ImportError go away.
> Symlinking the $JYTHON_HOME/Lib directory also made the ImportError go
> away.  But, both of these solutions seem dubious to me.  If I copy the Lib
> folder I feel like I have greater certainty that jython.jar and the Lib
> directory are a matched set, but my Lib directory is 99M in size!  If I
> symlink the Lib folder, I save the 99M but I lose the certainty that I have
> a matching jython.jar and Lib directory.
>
> I have also considered creating a custom jython.jar that contains Lib, or
> learning how to have a single, common jython.jar (and Lib) for all of my
> servlets, but before I head down those paths I thought I would ask to see
> what other people are doing.
>
> David
>
>
>
> ------------------------------------------------------------
> ------------------
>
> _______________________________________________
> Jython-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jython-users
>
>

------------------------------------------------------------------------------

_______________________________________________
Jython-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jython-users