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.

  • 2
    answer here may be helpful http://stackoverflow.com/questions/12229580/python-importing-a-sub-package-or-sub-module . try using `from mysql import connector` . Link provides a good explanation of submodule imports – Busturdust Jan 19 '16 at 18:52
  • thanks, but it doesn't seem to help me. – Chicago Excel User Jan 19 '16 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. – Chicago Excel User Jan 19 '16 at 20:45
  • 1
    OK, I'm still conflicted what's going on here. I've tried with pymysql library and no problems whatsoever. – Chicago Excel User Jan 19 '16 at 21:05

2 Answers2

1

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

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

Busturdust
  • 2,447
  • 24
  • 41