ModuleNotFoundError: 没有名为“MySQLdb"的模块 [英] ModuleNotFoundError: No module named 'MySQLdb'

查看:64
本文介绍了ModuleNotFoundError: 没有名为“MySQLdb"的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在完成我的一个 Flask 项目后,我和其他人一样将它上传到了 github.2-3 个月后,我在另一台机器上下载了整个 githube 存储库来运行它.但是,该应用程序无法运行,因为未找到提供以下消息的软件包

After finishing of one of my Flask projects, I uploaded it on github just like everybody else. after a 2-3 months period I downloaded the entire githube repository on another machine to run it. However, the app is not working because the packages are not found giving the following message

ModuleNotFoundError: 没有名为Flask"的模块

ModuleNotFoundError: No module named 'Flask'

所以我最终下载了从 Flask、SQLalchemy 等开始的所有软件包!但我被 MySQLdb 卡住了:

So I ended up downloading all packages starting from Flask, SQLalchemy,..etc! but I got stuck with MySQLdb:

(MYAPPENV) C:Usershpmyapp>python run.py
Traceback (most recent call last):
  File "run.py", line 1, in <module>
    from app import app
  File "C:Usershpmyappapp\__init__.py", line 4, in <module>
    from instance.config import engine
  File "C:Usershpmyappinstanceconfig.py", line 52, in <module>
    engine = create_engine("mysql://root:root@localhost/MYAPPDB")
  File "C:UsershpAppDataLocalProgramsPythonPython37-32libsite-packagessqlalchemyengine\__init__.py", line 425, in create_engine
return strategy.create(*args, **kwargs)
  File "C:UsershpAppDataLocalProgramsPythonPython37-32libsite-packagessqlalchemyenginestrategies.py", line 81, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
  File "C:UsershpAppDataLocalProgramsPythonPython37-32libsite-packagessqlalchemydialectsmysqlmysqldb.py", line 102, in dbapi
    return __import__('MySQLdb')
ModuleNotFoundError: No module named 'MySQLdb'

有人可以帮忙解决这个问题吗?我在 Windows 机器上使用 python37.我什至尝试下载诸如mysqlclient,..etc之类的包,但没有成功.

Could anybody please help with this issue? I am using python37 on windows machine. I even tried downloading packages such as mysqlclient,..etc but it didn't work out.

推荐答案

我读到 python3 不支持 mysqldb

I have read that mysqldb is not supported by python3

当您尝试连接到数据库时,您似乎默认使用 mysql db 连接到数据库!

And it looks like when you are trying to connect to your database you are using mysql db to connect to the database by default!

您需要通过编辑 DATABASE_URI 配置来更改它

但在您需要安装连接器扩展之前:

But before you need to install the connector extension :

使用这个命令:

pip install mysql-connector-python

根据本文档,您可以编辑您的 DATABASE_URI并像这样更改默认连接器:

And according to this documentation you can edit your DATABASE_URI and change the default connector like this :

DATABSE_URI='mysql+mysqlconnector://{user}:{password}@{server}/{database}'.format(user='your_user', password='password', server='localhost', database='dname')

我希望这会有所帮助...

I hope this will help...

这篇关于ModuleNotFoundError: 没有名为“MySQLdb"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆