Running a Flask application on Windows raises "an operation has been attempted for something that is not a socket"

When starting the base Flask application, I get this error in the shell and cannot find how to solve it.

 Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) <br/>
 Restarting with stat<br/>
 Debugger is active!<br/>
 Debugger pin code: 295-257-376<br/>
Exception in thread Thread-1:<br/>
Traceback (most recent call last):<br/>
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python35-32\lib\threading.py", line 923, in _bootstrap_inner
    self.run()<br/>
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python35-32\lib\threading.py", line 871, in run
    self._target(*self._args, **self._kwargs) <br/>
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python35-32\lib\site-packages\werkzeug\serving.py", line 656, in inner
    fd=fd)<br/>
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python35-32\lib\site-packages\werkzeug\serving.py", line 550, in make_server
    passthrough_errors, ssl_context, fd=fd)<br/>
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python35-32\lib\site-packages\werkzeug\serving.py", line 462, in __init__
    socket.SOCK_STREAM)<br/>
  File "C:\Users\Admin\AppData\Local\Programs\Python\Python35-32\lib\socket.py", line 446, in fromfd
    nfd = dup(fd)<br/>
OSError: [WinError 10038] An operation was attempted on something that is not a socket
from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def main():
    return render_template('main.html')

app.run(debug=True)
+4
source share
3 answers

You are currently trying to accomplish this with a global python installation. "Good practice" is to use virtual environments for python projects to support the separate installation of individual packages.

Start by starting pip install virtualenv

Then go to the projects folder and execute virtualenv example-virtual-env. This will create a new folder with your own python and pip installation. (It also supports virtual environments for Python 3.)

<projects_folder>\Scripts\activate, . pip install ( ).

pip install flask .

, CMD .

0

, , True. /, :

app.run(debug=False)

.

0

Python 3.6.0

: app.run( = False)

-

-1

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


All Articles