简体   繁体   中英

Why does my bottle server work start with the command python, but not python3?

Here is my code for my server.py file, taken from Bottle's documentation.

from bottle import route, run

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

run(host='localhost', port=8080, debug=True)

When I try to execute this in the terminal, it works when I do

python server.py

But when I execute

python3 server.py

I get the following error:

Traceback (most recent call last):
  File "server.py", line 1, in <module>
    from bottle import route, run
ModuleNotFoundError: No module named 'bottle'

It sounds like you've installed Bottle into your Python 2 environment, but not your Python 3 environment. (They are distinct; installing a package in one does not make it available in the other.)

Try pip3 install bottle or python3 -m pip install bottle and see if that resolves the error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM