ImportError: No module named 'MySQL'

后端 未结 17 1709
轮回少年
轮回少年 2020-12-12 17:40

I have downloaded the Connector/Python for MySQL successfully. I used the following code in Python\'s shell to test my connection:

import mysql.connector

相关标签:
17条回答
  • 2020-12-12 18:14

    I tried all the answers but not worked for me. It is a python version problem, in the end, I realized that python 3 scripts need explicit pip command for python 3, at least on ubuntu 18.

    python3 -m pip install mysql-connector
    
    0 讨论(0)
  • 2020-12-12 18:14

    You need to use anaconda to manage python environment dependencies. MySQL connector can be installed using conda installer

    conda install -c anaconda mysql-connector-python
    
    0 讨论(0)
  • 2020-12-12 18:14

    I have found another reason: If your program file's path contains space or special characters, then you'd get this error.

    0 讨论(0)
  • 2020-12-12 18:14

    For 64-bit windows

    install using wheel

    pip install wheel download from http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python
    

    For python 3.x:

    pip install mysqlclient-xxxxxxxxx-win_amd64.whl
    

    For python 2.7:

    pip install mysqlclient-xxxxxxxxx-win_amd64.whl
    
    0 讨论(0)
  • 2020-12-12 18:15

    This problem was a plague to me!!! The 100% solution is to forget using the mysql module: import mysql.connector, instead use pymysql via import pymysql. I installed it via the instructions: python3 -m pip install PyMySQL

    made a change to the: 1. Import statement 2. The connector 3. The cursor

    After that everything worked like a charm. Hope this helps!

    0 讨论(0)
  • 2020-12-12 18:20

    May be simple install from cli?

    pip3 install mysql-connector-python-rf
    

    Package name differs from import library name

    Or my universal variant in code:

    import pip
    pip.main(['install','mysql-connector-python-rf'])
    

    For new version of pip:

    from pip._internal import main
    main(['install','mysql-connector-python-rf'])
    

    It's better - install needed modules in running python installation (if many)

    0 讨论(0)
提交回复
热议问题