getting error ModuleNotFoundError:安装i时没有名为“mysql”的模块

2024-09-22 16:24:35 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我所有的安装mysql使用

pip3 install mysql

我可以在pip3列表中看到它,但是当我运行python应用程序时 我犯了个错误

ModuleNotFoundError: No module named 'mysql'

不确定问题出在哪里,下面是我用来查看是否有问题的代码 代码:

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)

Tags: importidaddressstatusmysqlelementmydbmycursor
1条回答
网友
1楼 · 发布于 2024-09-22 16:24:35

尝试安装

pip install mysql-connector-python mysql-connector-python

或者

pip install mysql-connector-python  allow-external mysql-connector-python

或者

pip install mysql-connector

相关问题 更多 >