Unable to import name 'create_connection' from 'sql'

53 views Asked by At

I am trying to use Flask on my pc but I keep getting an error whenever I import from the sql module. The error states:

ImportError: cannot import name 'create_connection' from 'sql' (C:<Directory to sql.py>)

# Imports
import flask
from flask import jsonify
from flask import request
import mysql.connector
from mysql.connector import Error
from sql import create_connection
from sql import execute_read_query

What can I do to fix this?

1

There are 1 answers

1
Ryan Lin On

I think it's the file path problem or package install issue. If you confirm your project path don't have the same file named "sql.py", you can try to below command:

pip uninstall python-sql

then

pip install python-sql