ImportError: 找不到名为 sqlalchemy 的模块。

9 浏览
0 Comments

ImportError: 找不到名为 sqlalchemy 的模块。

即使通过easy_install查询已安装,仍无法在Python中找到一个模块。

你有什么解决办法吗?

$ python -c "from flaskext.sqlalchemy import SQLAlchemy"
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named sqlalchemy
$ python -V
Python 2.7
$ sudo easy_install sqlalchemy
Searching for sqlalchemy
Best match: SQLAlchemy 0.7.7
Adding SQLAlchemy 0.7.7 to easy-install.pth file
Using /usr/lib/python2.7/site-packages
Processing dependencies for sqlalchemy
Finished processing dependencies for sqlalchemy

$ sudo pip install SQLAlchemy --upgrade 要求已经是最新的,SqlAlchemy已经安装在/usr/lib/python2.7/site-packages中。 正在清理...

尽管pip表示已经安装,但我在sys.path返回中找不到它们。

$ sudo python -c "import sys;print sys.path" ['',
'/usr/lib/python2.7/site-packages/Flask_SQLAlchemy-0.15-py2.7.egg',
'/usr/lib/python2.7/site-packages/Flask-0.8-py2.7.egg',
'/usr/lib/python2.7/site-packages/Jinja2-2.6-py2.7.egg',
'/usr/lib/python2.7/site-packages/Werkzeug-0.8.3-py2.7.egg',
'/usr/lib/python2.7/site-packages/Flask_WTF-0.5.2-py2.7.egg',
'/usr/lib/python2.7/site-packages/WTForms-0.6.3-py2.7.egg',
'/usr/lib/python2.7/site-packages/Flask_Mail-0.6.1-py2.7.egg',
'/usr/lib/python2.7/site-packages/blinker-1.2-py2.7.egg',
'/usr/lib/python2.7/site-packages/lamson-1.1-py2.7.egg',
'/usr/lib/python2.7/site-packages/python_daemon-1.6-py2.7.egg',
'/usr/lib/python2.7/site-packages/nose-1.1.2-py2.7.egg',
'/usr/lib/python2.7/site-packages/mock-0.8.0-py2.7.egg',
'/usr/lib/python2.7/site-packages/chardet-1.0.1-py2.7.egg',
'/usr/lib/python2.7/site-packages/lockfile-0.9.1-py2.7.egg',
'/usr/lib/python2.7/site-packages/Flask_FlatPages-0.2-py2.7.egg',
'/usr/lib/python2.7/site-packages/Markdown-2.1.1-py2.7.egg',
'/usr/lib/python2.7/site-packages/PyYAML-3.10-py2.7-linux-i686.egg',
'/usr/lib/python2.7/site-packages/uWSGI-1.0.3-py2.7.egg',
'/usr/lib/python2.7/site-packages/MySQL_python-1.2.3-py2.7-linux-i686.egg',
'/usr/lib/python27.zip', '/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload',
'/usr/lib/python2.7/site-packages',
'/usr/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']

admin 更改状态以发布 2023年5月24日
0
0 Comments

我刚刚遇到了同样的问题。显然,有一种新的分发方法,扩展代码不再存储在flaskext下。

来源: Flask CHANGELOG
这对我起作用:

from flask_sqlalchemy import SQLAlchemy

0
0 Comments

你已经安装了 flask-sqlalchemy 吗?看起来你已经安装了 SQLAlchemy,但是没有安装 Flask 扩展。请在你的项目虚拟环境中尝试运行 pip install Flask-SQLAlchemyPyPI 安装。

0