繁体   English   中英

收到错误 ModuleNotFoundError: No module named 'mysql' 当我安装它时

[英]getting error ModuleNotFoundError: No module named 'mysql' when i have installed it

大家好,我已经安装了 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)

尝试安装

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

或者

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

或者

pip install mysql-connector

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM