ImportError: No module named mysql.connector using Python2

前端 未结 12 2064
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-13 06:26

I have two files. The first one has the connection and the getting of data. I import mysql.connector. This file is called tasksSql.py

def get_users():
    im         


        
相关标签:
12条回答
  • 2020-12-13 06:42

    In my case, after the recent (Mac OS High Sierra) upgrade and the subsequent brew upgrade, I started to see the above error. I followed the above instructions but still got the same error message. Then I realised that I had to use python2 which points to the brew installed python rather than the os x installed one.

    0 讨论(0)
  • 2020-12-13 06:44

    In my case i already installed the package

    pip install mysql-connector
    pip install mysql-connector-python
    

    It giving me the same error so, i uninstall the both package by using

    pip uninstall mysql-connector
    pip uninstall mysql-connector-python
    

    and then again install the second package only

    pip install mysql-connector-python
    

    This solution worked for me.

    0 讨论(0)
  • 2020-12-13 06:49

    use the command below

    python -m pip install mysql-connector 
    
    0 讨论(0)
  • 2020-12-13 06:50

    This worked in ubuntu 16.04 for python 2.7:

    sudo pip install mysql-connector
    
    0 讨论(0)
  • 2020-12-13 06:54

    Depending on your python version and how you installed it, it is possible that mysql connector isn't installed, you can install it with pip

    To install mysql connector:

    pip install mysql-connector-python
    
    0 讨论(0)
  • 2020-12-13 07:00

    I was facing the similar issue. My env details - Python 2.7.11 pip 9.0.1 CentOS release 5.11 (Final)

    Error on python interpreter -

    >>> import mysql.connector
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: No module named mysql.connector
    >>>
    

    Use pip to search the available module -

     $ pip search mysql-connector | grep --color mysql-connector-python
    
    
    
    mysql-connector-python-rf (2.2.2)        - MySQL driver written in Python
    mysql-connector-python (2.0.4)           - MySQL driver written in Python
    

    Install the mysql-connector-python-rf -

    $ pip install mysql-connector-python-rf
    

    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
    >>>
    
    0 讨论(0)
提交回复
热议问题