[bottlepy] ImportError: No module named bottle

1,625 views
Skip to first unread message

Volodymyr GL

unread,
May 21, 2010, 6:18:06 AM5/21/10
to bottlepy
I have installed apache and mode_wsgi. There are two files in website
folder: bottle.py and app.py

This code in app.py runs ok
#**********************************************************************
#-*- coding: utf-8 -*-
import pprint
def wsgi_app(environ, start_response):
""" Display the contents of the environ dictionary."""
# produce some content
output = pprint.pformat(environ)

# send first header and status
status = '200 OK'
headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, headers)

# wsgi apps should return and iterable, the following is
acceptable too :
# return [output]
yield output

# mod_wsgi need the *application* variable to serve our small app
application = wsgi_app
#**********************************************************************


but when i replace it with helloworld:


#**********************************************************************
from bottle import route, run

@route('/')
def index():
return 'Hello World!'

# File: /var/www/yourapp/app.wsgi

# Change working directory so relative paths (and template lookup)
work again
os.chdir(os.path.dirname(__file__))

import bottle
application = bottle.default_app()

#**********************************************************************

I get internal error.

[Fri May 21 13:11:50 2010] [error] [client 127.0.0.1] mod_wsgi
(pid=5320): Target WSGI script 'C:/www/app.py' cannot be loaded as
Python module.
[Fri May 21 13:11:50 2010] [error] [client 127.0.0.1] mod_wsgi
(pid=5320): Exception occurred processing WSGI script 'C:/www/app.py'.
[Fri May 21 13:11:50 2010] [error] [client 127.0.0.1] Traceback (most
recent call last):
[Fri May 21 13:11:50 2010] [error] [client 127.0.0.1] File "C:/www/
app.py", line 2, in <module>
[Fri May 21 13:11:50 2010] [error] [client 127.0.0.1] from bottle
import route, run
[Fri May 21 13:11:50 2010] [error] [client 127.0.0.1] ImportError: No
module named bottle

--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottle.paws.de/ for news and documentation.

Tarek Ziadé

unread,
May 21, 2010, 6:24:05 AM5/21/10
to bott...@googlegroups.com
On Fri, May 21, 2010 at 12:18 PM, Volodymyr GL <int...@gmail.com> wrote:
> I have installed apache and mode_wsgi. There are two files in website
> folder: bottle.py and app.py
>
[..]
> [Fri May 21 13:11:50 2010] [error] [client 127.0.0.1] ImportError: No
> module named bottle

This means mod_wsgi doesn't see the bottle module.

You can add a WSGIPythonPath directive to add the directory where its located:

http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIPythonPath

*or* change sys.path in your wsgi script, so you append the directory :

import sys; sys.path.insert(0, THE_DIR)

The first solution is cleaner I guess...

Also, make sure mod_wsgi uses the same Python, you have used manually
to run your app

Regards
Tarek

--
Tarek Ziadé | http://ziade.org
Reply all
Reply to author
Forward
0 new messages