miguelgrinberg / Flask-SocketIO-Chat

A simple chat application that demonstrates how to structure a Flask-SocketIO application.
http://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent
MIT License
676 stars 242 forks source link

failed to install requirements on windows due to greenlet #41

Closed JiewenGuan closed 1 year ago

JiewenGuan commented 1 year ago

got this output when attempting to install requirements:

..."Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/ [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for greenletFailed to build greenlet ERROR: Could not build wheels for greenlet, which is required to install pyproject.toml-based projects

it may be related with my python installation from windows store.

attempted to manually install it and found only flask_wtf and flask_socketio is required be manually installed to run this example, other requirements like flask and jinja is automatically installed, and greenlet is not included, also version of package does not affect the function. Therefore, I'm suggesting a slimmed down requirements.txt file.

rayanth commented 1 year ago

the error on greenlet is because you don't have a C++ compiler installed, or not configured, or not configured correctly that Python can find it.

You're semi-correct on requirements, but I argue against what you're trying to advocate.

Flask is a requirement of Flask-WTF, therefor installing Flask-WTF will install Flask implicitly. Likewise, Jinja is a requirement of Flask, so installing Flask (via Flask-WTF) will install Jinja implicitly... however, the requirements.txt file is very rarely manually created or edited - it's created via pip freeze > requirements.txt which will add every package from the virtual environment to the requirements.txt file. If it were then manually edited, and a new package added later, and the requirements.txt updated with a pip freeze, then the creator has to go back in and manually edit it again... for a small project that may not sound like a big deal, but for a large project, it's a nightmare.

Removing requirements because they are implied as dependencies of other requirements is a good way to have a big problem down the road when a dependency changes. Besides, as the Zen of Python says: Explicit is better than implicit.

miguelgrinberg commented 1 year ago

A failure when installing greenlet usually means that the greenlet package does not have a wheel package for the version of Python and/or operating system. I have seen this error recently when using Python 3.12, so the interim solution is to use Python 3.11, which installs greenlet from a wheel. Eventually the greenlet team will push wheels for 3.12 and everything will be good again.