简体   繁体   中英

Python 3.4 MySQL Connector Not Found Only When Running a Script File

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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