收到错误ModuleNotFoundError:安装了没有名为“ mysql”的模块

时间:2019-11-16 04:19:35

标签: python mysql

大家好,我已经使用

安装了mysql。
pip3 install mysql

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

  

ModuleNotFoundError:没有名为“ 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)

1 个答案:

答案 0 :(得分:1)

尝试安装

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

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

pip install mysql-connector