No module named 'mysql'

Viewed 1605

I've created a Python script to store data in MySQL. It works properly in PyCharm. When converted to an exe file it does not work.

This is traceback from the command line:

Traceback (most recent call last):
  File "myscript.py", line 1, in <module>
    import mysql.connector
ModuleNotFoundError: No module named 'mysql'
[8428] Failed to execute script 'myscript' due to unhandled exception!

The command to create the exe:

pyinstaller --onefile --console CoinVolumes.py

I also tried auto-py-to-exe but got the same error. Mysql is installed.

3 Answers

use this command:

pip install mysql-connector-python

after that verify:

$ python
Python 2.7.11 (default, Apr 26 2016, 13:18:56)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
>>>

In Python 3.6.9 I can use Pip 3 and do following:

pip3 install mysql
pip3 install mysql-connector-python

You would need to run the mysql server yourself. Pyinstaller is working properly, the problem here is that mysql server is not part of python, therefore you need to start the server mannualy. An alternative is to use sqlite, which does not require a server. It is built into standard python, no need for installing anything.

Related