0

I have downloaded and installed the Connector/Python for MySQL successfully with:

pip install mysql-connector-python

but when i run my Python File in terminal (Visual Studio Code) shows me this error:

ModuleNotFoundError: No module named 'mysql'

this is my code:

import mysql.connector

database = mysql.connector.connect(
    host="localhost",
    user="root",
    passwd=""
    #database="master_python"
)

I have tried to install mysql-connector-python-rf with:

pip install mysql-connector-python-rf

but shows me a big, red and awful error:

ERROR: Command errored out with exit status 1:
     command: 'c:\program files\python38\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Enrique Rubio\\AppData\\Local\\Temp\\pip-install-w1fo5muv\\mysql-connector-python-rf_a462ab4d49084651a288ddeacc8db2f3\\setup.py'"'"'; __file__='"'"'C:\\Users\\Enrique Rubio\\AppData\\Local\\Temp\\pip-install-w1fo5muv\\mysql-connector-python-rf_a462ab4d49084651a288ddeacc8db2f3\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Enrique Rubio\AppData\Local\Temp\pip-record-5uwbo9pj\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\Enrique Rubio\AppData\Roaming\Python\Python38\Include\mysql-connector-python-rf'
         cwd: C:\Users\Enrique Rubio\AppData\Local\Temp\pip-install-w1fo5muv\mysql-connector-python-rf_a462ab4d49084651a288ddeacc8db2f3\
    Complete output (6 lines):
    usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
       or: setup.py --help [cmd1 cmd2 ...]
       or: setup.py --help-commands
       or: setup.py cmd --help

    error: option --single-version-externally-managed not recognized
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\program files\python38\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Enrique Rubio\\AppData\\Local\\Temp\\pip-install-w1fo5muv\\mysql-connector-python-rf_a462ab4d49084651a288ddeacc8db2f3\\setup.py'"'"'; __file__='"'"'C:\\Users\\Enrique Rubio\\AppData\\Local\\Temp\\pip-install-w1fo5muv\\mysql-connector-python-rf_a462ab4d49084651a288ddeacc8db2f3\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Enrique Rubio\AppData\Local\Temp\pip-record-5uwbo9pj\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\Enrique Rubio\AppData\Roaming\Python\Python38\Include\mysql-connector-python-rf' Check the logs for full command output.

I can't figure out why MySQL is not being recognized. PLEASE someone can help me.

  • See if this answer solves your issue: https://stackoverflow.com/questions/22100757/can-not-get-mysql-connector-python-to-install-in-virtualenv – Ricardo Udenze Jan 02 '21 at 21:47

1 Answers1

0

Can you confirm that you only have one python version installed on your system?

If you have indeed multiple versions installed, try pip3 or the respective sub-version.

If that does not help, try downloading and installing the binary from here:

https://dev.mysql.com/downloads/connector/python/

Manuel Huppertz
  • 310
  • 2
  • 9
  • When i install the binary from that link shows me an error: insuficcient privileges to access to this directory... – Sebastián Rubio Jan 02 '21 at 22:16
  • Please do not recommend `pip3` script and things like that, instead it is always better to recommend to call _pip_'s executable module for a specific Python interpreter: `path/to/pythonX.Y -m pip` -- https://snarky.ca/why-you-should-use-python-m-pip/ – sinoroc Jan 02 '21 at 22:41