Sanic: Cannot run Sanic!!

Created on 19 Oct 2017  ·  4Comments  ·  Source: sanic-org/sanic

I'm newbie. I try to install and run sanic as the example
in sanic.py:

from sanic import Sanic
from sanic.response import text

app = Sanic(__name__)

@app.route("/")
async def test(request):
    return text('Hello world!')

app.run(host="0.0.0.0", port=8000, debug=True)

in bash, i try to run it, but cause this error:

cabox@box-codeanywhere:~/workspace$ sudo python3.5 -m pip install sanic
Requirement already satisfied (use --upgrade to upgrade): sanic in /usr/local/lib/python3.5/dist-packages
Cleaning up...
cabox@box-codeanywhere:~/workspace$ python3.5 sanic.py
Traceback (most recent call last):
  File "sanic.py", line 1, in <module>
    from sanic import Sanic
  File "/home/cabox/workspace/sanic.py", line 1, in <module>
    from sanic import Sanic
ImportError: cannot import name 'Sanic'

this is my environment:
python3 = python3.4
python3.5=python3.5

Please Help

Most helpful comment

Name your file something other than sanic.py

All 4 comments

Name your file something other than sanic.py

The problem was identified. Can this issue be closed?

Sometimes it caused by Python Environment.
Ex:
I built Python3.7 and pip3.
I installed sanic via pip3.

  1. if do it python3 CLI or ran python3 test_.py >>
    it will raise "ModuleNotFoundError: No module named 'sanic' "
  2. If use python3.7 test_.py
    it will work as well

Probably python3 is not the same as python3.7.

$ which python3
$ which python3.7
$ # or
$ python3 --version
$ python3.7 --version
Was this page helpful?
0 / 5 - 0 ratings