import MySQLdb 异常

来源:3-2 python链接mysql数据库

慕的地5299434

2018-12-03

老师,好

我在mac系统配置环境,python3.6.7,mysql版本5.7.19mysql连接器 mysql-connector-c和mysqlclient 没有使用虚拟机

brew install mysql-connector-c
pip install mysqlclient

以上安装未出现报错

mac终端测试,没有提示任何异常
import MySQLdb
Python 3.6.7 (v3.6.7:6ec5cf24b7, Oct 20 2018, 03:02:14)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.

import MySQLdb

在编辑器代码测试 提示异常

调试
import MySQLdb

def get_conn(self):
try:
self.com = MySQLdb.connect(
host=“localhost”,
port=3306,
user=“root”,
password=“POIJKL”,
db=“MyDb”,
charse=“utf8”)
except MySQLdb.Error as e:
print(“Error %d:%s” % (e.arge[0],e.args[1]))
return self.con

异常信息:Traceback (most recent call last):
File “/Users/adi/PycharmProjects/test/venv/test.py”, line 1, in
import MySQLdb
ModuleNotFoundError: No module named ‘MySQLdb’

写回答

1回答

NavCat

2018-12-03

你使用绝对路径的python来执行一下试试

0
0

Python操作三大主流数据库-MySQL+MongoDB+Redis

一次实战同时掌握Python操作MySQL,MongoDB,Redis 三大数据库使用技巧

2024 学习 · 374 问题

查看课程