0

I'm having a problem running my script file.

This is on Windows 7.

I've downloaded and installed Python 3.4

Downloaded and installed the connector https://dev.mysql.com/downloads/connector/python/

When I run python in my command prompt line by line the script works fine with no problems and returns the data from my database.

python C:\Users\myUser\Documents\python\mysql.py

I get

ImportError: No module named 'mysql.connector'; 'mysql' is not a package

So for some reason it isn't able to find the module when I run the script from the file. It's the first line in it BTW.

import mysql.connector

But it works fine if I just execute Python in my command prompt and then run the line.

4
  • 2
    answer here may be helpful stackoverflow.com/questions/12229580/… . try using from mysql import connector . Link provides a good explanation of submodule imports Commented Jan 19, 2016 at 18:52
  • thanks, but it doesn't seem to help me. Commented Jan 19, 2016 at 20:43
  • I ran import sys print(sys.path) from a file in the same folder to see what Python sees as the folder to look for the library, and it includes the correct folder as the last element of the list. The folder includes the "mysql" folder and another internal "connector" folder and all the init files are there too. Commented Jan 19, 2016 at 20:45
  • 1
    OK, I'm still conflicted what's going on here. I've tried with pymysql library and no problems whatsoever. Commented Jan 19, 2016 at 21:05

2 Answers 2

1

Change the name from mysql.py to mysqlxx.py. It's looking in your file instead of the module.

Sign up to request clarification or add additional context in comments.

Comments

0

I am assuming python C:\Users\myUser\Documents\python\mysql.py is a custom script, and is not the mysql connector

Unforunately for you, the name of your script shadows the exact name of the mysql module

I believe this may be causing a clash of modules, and that if you renamed your script to something more agnostic like mysql_test.py which doesnt clash with the installed module, you would be okay

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.