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

查看:1142
本文介绍了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:\Users\hp\myapp>python run.py
Traceback (most recent call last):
  File "run.py", line 1, in <module>
    from app import app
  File "C:\Users\hp\myapp\app\__init__.py", line 4, in <module>
    from instance.config import engine
  File "C:\Users\hp\myapp\instance\config.py", line 52, in <module>
    engine = create_engine("mysql://root:root@localhost/MYAPPDB")
  File "C:\Users\hp\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sqlalchemy\engine\__init__.py", line 425, in create_engine
return strategy.create(*args, **kwargs)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sqlalchemy\engine\strategies.py", line 81, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sqlalchemy\dialects\mysql\mysqldb.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

根据此文档,您可以编辑DATABSE_URI并更改默认的连接器,如下所示:

And according to this documentation you can edit your DATABSE_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天全站免登陆