Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Python
  3. Question
Python

ImportError: No module named mysql.connector using Python2

Asked by Justin Stewart Mar 8, 2021 1.4K views 1 answer
Share

About this question

I am having two files. The first one has a connection and the getting of data. I am importing mysql.connector. This file is called tasksSql.py

def get_users(): import mysql.connector con = mysql.connector.connect(user='****', password='*****', host='127.0.0.1', database='tasks') c = con.cursor() users = [] c.execute("""SELECT * FROM task_user""") for row in c: user = { 'id': row[0], 'first': row[1], 'last': row[2], 'email': row[3], 'password': row[4], 'creation_date': row[5] } users.append(user) c.close() return users

When I am running this file singly it works and returns the data.

Another file is named tasks.py where I am going to be importing this file, however, this is not working! When I import the file, it gives me the following error:

ImportError: No module named mysql.connector

Where am I doing wrong?

Your answer

1 Answer

More Python discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Python Blogs

Guides, tips and career advice on Python from JanBask experts.