本文介绍了ImportError:未安装带有两个Python版本的名为"flask_sqlalchemy"的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试运行具有以下导入内容的文件:

Tried running a file with the following imports:

from flask_sqlalchemy import sqlalchemy
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker

收到以下错误:

ImportError: No module named 'flask_sqlalchemy'

已安装SQLAlchemy.尽管如此,我还是尝试将其重新安装到将要使用的目录中.我知道了:

SQLAlchemy is installed. Still, I tried to reinstall into the directory in which it will be used. I got this:

The directory '/Users/_/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/_/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: Flask-SQLAlchemy in /Library/Python/2.7/site-packages (2.3.2)
Requirement already satisfied: Flask>=0.10 in /Library/Python/2.7/site-packages (from Flask-SQLAlchemy) (1.0.2)
Requirement already satisfied: SQLAlchemy>=0.8.0 in /Library/Python/2.7/site-packages (from Flask-SQLAlchemy) (1.2.10)
Requirement already satisfied: Jinja2>=2.10 in /Library/Python/2.7/site-packages (from Flask>=0.10->Flask-SQLAlchemy) (2.10)
Requirement already satisfied: itsdangerous>=0.24 in /Library/Python/2.7/site-packages (from Flask>=0.10->Flask-SQLAlchemy) (0.24)
Requirement already satisfied: Werkzeug>=0.14 in /Library/Python/2.7/site-packages (from Flask>=0.10->Flask-SQLAlchemy) (0.14.1)
Requirement already satisfied: click>=5.1 in /Library/Python/2.7/site-packages (from Flask>=0.10->Flask-SQLAlchemy) (6.7)
Requirement already satisfied: MarkupSafe>=0.23 in /Library/Python/2.7/site-packages (from Jinja2>=2.10->Flask>=0.10->Flask-SQLAlchemy) (1.0)

关于我不拥有目录的问题是不正确的.我是这台机器上唯一的一个.我拥有一切.

The bit about me not owning the directory is incorrect. I'm the only one on this machine. I own everything.

无论如何,我返回以重新运行该文件并得到相同的错误消息.因此,它已安装但尚未安装,或者至少对我不可用.

Anyway, I go back to rerun the file and get the same error message. So, it's installed, but not installed or, at the very least, not available to me.

当我注释掉其中一个导入语句时看到的一条错误消息如下:

One error message I saw when I commented out one of the import statements read as follows:

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/sqlalchemy/engine/strategies.py

我不知道如何解决此问题并启动并运行SQLAlchemy.我已经烧了1.5个小时以上.列出的最后一个错误表明拥有2个版本的python可能与此有关.

I have no clue how to fix this and get SQLAlchemy up and running. I've burned over 1.5 hours on it. The last error listed suggests having 2 versions of python may have something to do with it.

您对补救措施的想法将不胜感激.

Your thoughts on a remedy would be appreciated.

推荐答案

最终,在我发布上述问题后,终于解决了这个问题.

Ultimately, I resolved this issue ages after I posted the above question.

解决方法是运行所有软件包更新并通过Anaconda安装并在Spyder中完成我的工作.

The fix was to run all package updates and installs thru Anaconda and do my work in Spyder.

吸取的教训很简单:一旦开始将Anaconda用作Python的通用环境,则默认情况下,通过conda install或pip进行的所有更新都将由Anaconda编排并放置在您的系统中.

The lesson learned was simple: Once you start using Anaconda as your go-to environment for all things Python, all updates -- made via conda install or pip -- will be orchestrated and placed in your system by Anaconda by default.

这篇关于ImportError:未安装带有两个Python版本的名为"flask_sqlalchemy"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 20:27
查看更多