Search code examples
pythonpycharmwaitress

ImportError: cannot import name 'serve' from 'waitress'


from waitress import serve              # error line 
import app                              # python file where flask code is written
serve(app.app,port=8000,thread=55) 
  1. Python version : 3.7
  2. waitress version : try with 1.4.1 and 1.3.0*

Stack Trace

C:\Users\ashish.kamble\ModelDeployment\Scripts\python.exe C:/Users/ashish.kamble/PycharmProjects/ModelDeployment/waitress.py
Traceback (most recent call last):
  File "C:/Users/ashish.kamble/PycharmProjects/ModelDeployment/waitress.py", line 1, in <module>
    from waitress import serve
  File "C:\Users\ashish.kamble\PycharmProjects\ModelDeployment\waitress.py", line 1, in <module>
    from waitress import serve
ImportError: cannot import name 'serve' from 'waitress' (C:\Users\ashish.kamble\PycharmProjects\ModelDeployment\waitress.py)

Process finished with exit code 1

Solution

  • Your Error occurred because of your file name is waitress.py.

    When you run your code your waitress keyword work as an object of your file. There for if you want to get rid of from that error rename your python file into which not represent your libraries.

    Addition -: It is better to install libraries using Pycharm project interpreter. Follow these steps to install libraries using interpreter.