Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:ImportError没有名为mysql.connector的模块_Python_Python 2.7_Mysql Python_Importerror_Mysql Connector Python - Fatal编程技术网

Python:ImportError没有名为mysql.connector的模块

Python:ImportError没有名为mysql.connector的模块,python,python-2.7,mysql-python,importerror,mysql-connector-python,Python,Python 2.7,Mysql Python,Importerror,Mysql Connector Python,我刚刚从python脚本创建了一个exe,当我试图运行它时,它没有显示出来 然后,我尝试从cmd运行它,我得到了下面的ImportError: Traceback (most recent call last): File "tkintertest2.py", line 17, in <module> File "Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_mo

我刚刚从
python
脚本创建了一个
exe
,当我试图运行它时,它没有显示出来

然后,我尝试从
cmd
运行它,我得到了下面的
ImportError

Traceback (most recent call last):
  File "tkintertest2.py", line 17, in <module>
  File "Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 
389, in load_module
  File "MySQL.py", line 1, in <module>
ImportError: No module named mysql.connector
Failed to execute script tkintertest2
回溯(最近一次呼叫最后一次):
文件“tkintertest2.py”,第17行,在
文件“Lib\site packages\PyInstaller\loader\pyimod03\u importers.py”,第行
389,在加载模块中
文件“MySQL.py”,第1行,在
ImportError:没有名为mysql.connector的模块
无法执行脚本tkintertest2

如何解决这个问题?我已经使用
pip
install和
conda
install安装了
mysql.connector

根据pyinstaller文档,pyinstaller没有找到python模块,因此请明确地将其包括在内,如下所示:

pyinstaller --hidden-import mysql.connector myscript.py

您是如何使用python创建exe的?可能模块没有与脚本一起放入exe文件(可能是$PATH问题)。您是否验证了可以在python解释器中导入mysql.connector?如果有名为
mysql.py
的脚本文件,可以重命名
mysql.py
@NuclearPeon,我使用pyinstaller创建
exe
。我以前试过运行脚本,但效果很好。@McGrady我刚刚更改了脚本,并尝试再次运行
exe
,但仍然出现相同的错误。@NuclearPeon我试过了,效果很好!非常感谢
pyinstaller——隐藏导入mysql.connector myscript.py