ho creato una web app pitone con questa struttura di directory:non può importare il modulo
# cd /usr/local/www/myapp
modules
layout
__init__.py
layout.py
packages
public
myapp.wsgi
ho impostato il mio PYTHONPATH a:
/usr/local/www/myapp/modules:/usr/local/www/myapp/packages
In myapp.wsgi che cerco di fare:
import layout
Ma sto ricevendo errore del server interno. Perché?
Questo è il mio myapp.wsgi (se mi tolgo la linea di layout di importazione, funziona):
import sys
import wsgiref
import layout
def application(environ, start_response):
response_status = '200 OK'
response_body = 'Hello! '
response_headers = []
content_type = ('Content-type', 'text-plain')
content_length = ('Content-Length', str(len(response_body)))
response_headers.append(content_type)
response_headers.append(content_length)
start_response(response_status, response_headers)
return [response_body]
messaggio di errore completo sto ottenendo:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
La mia configurazione virtualhost:
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
ServerAdmin [email protected]
DocumentRoot /usr/local/www/myapp/public
<Directory /usr/local/www/myapp/public>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias//usr/local/www/myapp/myapp.wsgi
<Directory /usr/local/www/myapp>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Errore da /var/log/httpd-error.log:
[Fri Jan 20 15:31:03 2012] [error] [client 192.168.201.123] mod_wsgi (pid=1725): Target WSGI script '/usr/local/www/myapp/myapp.wsgi' cannot be loaded as Python module.
[Fri Jan 20 15:31:03 2012] [error] [client 192.168.201.123] mod_wsgi (pid=1725): Exception occurred processing WSGI script '/usr/local/www/myapp/myapp.wsgi'.
[Fri Jan 20 15:31:03 2012] [error] [client 192.168.201.123] Traceback (most recent call last):
[Fri Jan 20 15:31:03 2012] [error] [client 192.168.201.123] File "/usr/local/www/myapp/myapp.wsgi", line 3, in <module>
[Fri Jan 20 15:31:03 2012] [error] [client 192.168.201.123] import layout
[Fri Jan 20 15:31:03 2012] [error] [client 192.168.201.123] ImportError: No module named layout
uscita di sys.path stampa:
Almeno includere il messaggio di errore completo ed esatto che si sta ottenendo. – unwind
Come stai usando il web server? È molto probabile che non si usi il proprio ambiente, quindi l'impostazione di PYTHONPATH per la propria shell non sarà di aiuto. – geoffspear
Sto usando Apache mod_wsgi e ho creato un host virtuale per/usr/local/www/myapp. –