Bottle: cannot import route

I get the following error:

(virtualenv)[ chirdeep@fedora-desktop ~]$ python programs/python/myrestapi.py Traceback (most recent call last): File "programs/python/myrestapi.py", line 2, in <module> import bottle File "/home/chirdeep/programs/python/bottle.py", line 1, in <module> from bottle import route, run ImportError: cannot import name route 

I have python 2.7.3 and 3.2.3. (virtualenv) points to python3, and I installed here the bottle and its available under the package site.

I can import the bottle when I'm under the python console after activating the environment.

 (virtualenv)[ chirdeep@fedora-desktop ~]$ python Python 3.2.3 (default, Jul 26 2012, 22:03:19) [GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import bottle >>> 

Any help would be greatly appreciated, driving me crazy.

thanks

+6
source share
2 answers

Your own Python file is called bottle.py :

 File "/home/chirdeep/programs/python/bottle.py", line 1, in <module> 

So the real bottle.py obscured by your own file. Since your own file does not contain route and run , this fails:

 from bottle import route, run 

Rename your own file, possibly mybottle.py .

+16
source

I assume the problem is with the collision of your program namespace with the bottle. Ie: Python is trying to import the route from /home/chirdeep/programs/python/bottle.py, and not into bottle.py in the site packages.

Try renaming your program file.

+2
source

Source: https://habr.com/ru/post/921716/


All Articles