简体   繁体   English

仅在运行脚本文件时找不到Python 3.4 MySQL Connector

[英]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. 这是在Windows 7上。

I've downloaded and installed Python 3.4 我已经下载并安装了Python 3.4

Downloaded and installed the connector https://dev.mysql.com/downloads/connector/python/ 下载并安装了连接器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时,脚本运行正常,没有问题,并从数据库返回了数据。

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. 但是,如果我只是在命令提示符下执行Python,然后运行该行,则效果很好。

Change the name from mysql.py to mysqlxx.py. 将名称从mysql.py更改为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 我假设python C:\\Users\\myUser\\Documents\\python\\mysql.py是自定义脚本,而不是mysql连接器

Unforunately for you, the name of your script shadows the exact name of the mysql module 不幸的是,脚本名称掩盖了mysql模块确切名称

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 我相信这可能会导致模块冲突,并且如果您将脚本重命名为更不可知的名称(例如mysql_test.py ,而该名称与已安装的模块不冲突,则可以

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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