收到错误 ModuleNotFoundError: 我安装时没有名为“mysql"的模块 [英] getting error ModuleNotFoundError: No module named 'mysql' when i have installed it
本文介绍了收到错误 ModuleNotFoundError: 我安装时没有名为“mysql"的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我已经使用
pip3 install mysql
并且我可以在 pip3 列表中看到它,但是当我运行 python 应用程序时我收到一个错误
and I can see it in the pip3 list, but when I run the python app I am getting a error
ModuleNotFoundError: 没有名为mysql"的模块
ModuleNotFoundError: No module named 'mysql'
不确定是什么问题,这是我用来查看是否有问题的代码代码:
Not sure what the issue is, here is the code I am using to see if it might be something the code:
import urllib.parse
import requests
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="*******",
database="flightdata"
)
mycursor = mydb.cursor()
main_api = 'https://www.sydneyairport.com.au/_a/flights/?query=&flightType=departure&terminalType=domestic&date=2019-11-10&sortColumn=scheduled_time&ascending=true&showAll=true'
address = 'lhr'
url = main_api + urllib.parse.urlencode({address: address})
response_data = requests.get(url).json()
for element in response_data['flightData']:
flight_id = element['id']
airline = element['airline']
destination = element['destinations']
flightNumbers = element['flightNumbers']
scheduledTime = element['scheduledTime']
estimatedTime = element['estimatedTime']
scheduledDate = element['scheduledDate']
latestTime = element['latestTime']
status = element['status']
statusColor = element['statusColor']
sql = "INSERT INTO flightinfo (id, airline, destinations, flightNumbers, scheduledTime, estimatedTime, scheduledDate, latestTime, status, statusColor ) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s))"
val = [
(flight_id, airline, destination, flightNumbers, scheduledTime, estimatedTime, estimatedTime, scheduledDate, latestTime, status, statusColor),
]
mycursor.executemany(sql, val)
mydb.commit()
print(mycursor.rowcount, "was inserted.")
# print(airline, destination, flightNumbers, status, statusColor)
推荐答案
尝试安装
pip install mysql-connector-python mysql-connector-python
或
pip install mysql-connector-python --allow-external mysql-connector-python
或
pip install mysql-connector
这篇关于收到错误 ModuleNotFoundError: 我安装时没有名为“mysql"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文