Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name route in python bottle

Tags:

python

I am trying to start learning python bottle framework, I've installed python 2.7.11, and installed pip too, I've installed bottle using

pip install bottle
Collecting bottle
  Using cached bottle-0.12.9.tar.gz
Installing collected packages: bottle
  Running setup.py install for bottle ... done
Successfully installed bottle-0.12.9

Now I tried to run the example code from bottle website

from bottle import route, run, template
@route('/hello/<name>')
def index(name):
    return template('<b>Hello {{name}}</b>!', name=name)
run(host='localhost', port=8080)

when I run this code it throws the following error

Traceback (most recent call last):
  File "C:/Users/SID/Desktop/bottle.py", line 1, in <module>
    from bottle import route, run, template
  File "C:/Users/SID/Desktop\bottle.py", line 1, in <module>
    from bottle import route, run, template
ImportError: cannot import name route

I don't know what went wrong could some one guide me, Is it the error with the code? or in bottle installation?

Note: I Tried python 3.4.3 too still facing same error while running program and I'm using windows 8.1 in virtual box

like image 629
Sundararajan Avatar asked Sep 14 '26 12:09

Sundararajan


1 Answers

You have bottle.py file within your project folder. Problem occurred because python module C:/Users/SID/Desktop/bottle.py shadowed bottle.py module which installed by pip. Rename file which shadow real bottle.py module to fix import problem.

Location of file which shall be renamed is C:/Users/SID/Desktop/bottle.py.

like image 90
Andriy Ivaneyko Avatar answered Sep 17 '26 05:09

Andriy Ivaneyko