How to manually install Flask extensions?

和自甴很熟 提交于 2019-12-04 10:58:07

The solution is to put the flask_login.py file in the same directory as my app.py file. No modification of the flask/ext/__init__.py file is necessary.

The flask.ext module is intended only as a an extension importer, not a repository for installed extensions. Based on the import path, I thought the flask/ext folder was where extensions were to be copied. This was incorrect. Extensions simply need to be somewhere on the python path.

Python doesn't throw the exception in your case, this Flask module is responsible for modifying the standard import hook in the ext folder: https://github.com/mitsuhiko/flask/blob/master/flask/exthook.py

So, I don't think putting flask_login.py into flask/ext is the right way to use extensions in Flask. The documentation recommends to use pip install flask-login or python setup.py install. After that you can do:

import flask_login

If you still want to do it manually, remove the setup() call from ext/__ init__.py. It probably has a good reason why the Flask guys did it this way though :-)

Right, but the point was to manually install everything so it could be self-contained in a version control repository that won't require additional installs. I've looked at the setup.py file but can't determine how it achieves the installation. – Soviut Oct 25 at 10:06

Why not use virtualenv to achieve this? You can push your env to source control as well, although that's not normal usage.

See: http://www.virtualenv.org/en/latest/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!