Search code examples
pythonpython-2.7mysql-pythonimporterrormysql-connector-python

Python: ImportError no module named mysql.connector


I just created an exe from python script and when I tried to run it, it did not show up.

Then, I tried to run it from cmd and I got ImportError below:

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

How to solve this? I have installed mysql.connector using both pip install and conda install.


Solution

  • According to the pyinstaller docs here, pyinstaller is not finding the python module, so explicitly include it like so:

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