Installing MySQL-python

前端 未结 8 626
夕颜
夕颜 2020-11-28 19:58

I got the below failure while trying to get MySQL-python installed on my Ubuntu/Linux Box.From the below it seem like the issue is sh: mysql_config: not found C

相关标签:
8条回答
  • 2020-11-28 20:26

    this worked for me on python 3

    pip install mysqlclient

    0 讨论(0)
  • 2020-11-28 20:31

    On Ubuntu it is advised to use the distributions repository. So installing python-mysqldb should be straight forward:

    sudo apt-get install python-mysqldb
    

    If you actually want to use pip to install, which is as mentioned before not the suggested path but possible, please have a look at this previously asked question and answer: pip install mysql-python fails with EnvironmentError: mysql_config not found

    Here is a very comprehensive guide by the developer: http://mysql-python.blogspot.no/2012/11/is-mysqldb-hard-to-install.html

    To get all the prerequisites for python-mysqld to install it using pip (which you will want to do if you are using virtualenv), run this:

    sudo apt-get install build-essential python-dev libmysqlclient-dev
    
    0 讨论(0)
  • 2020-11-28 20:34
    1. find the folder: sudo find / -name "mysql_config" (assume it's "/opt/local/lib/mysql5/bin")

    2. add it into PATH:export PATH:export PATH=/opt/local/lib/mysql5/bin:$PATH

    3. install it again

    0 讨论(0)
  • 2020-11-28 20:35

    Reread the error message. It says:

    sh: mysql_config: not found

    If you are on Ubuntu Natty, mysql_config belongs to package libmysqlclient-dev

    0 讨论(0)
  • 2020-11-28 20:36

    In python3 with virtualenv on a Ubuntu Bionic machine the following commands worked for me:

    sudo apt install build-essential python-dev libmysqlclient-dev
    sudo apt-get install libssl-dev
    pip install mysqlclient
    
    0 讨论(0)
  • 2020-11-28 20:41

    You have 2 options, as described bellow:


    Distribution package like Glaslos suggested:

    # sudo apt-get install python-mysqldb
    

    In this case you can't use virtualenv no-site-packages (default option) but must use:

    # virtualenv --system-site-packages myenv
    

    Use clean virtualenv and build your own python-mysql package.

    First create virtualenv:

    # virtualenv myvirtualenv
    # source myvirtualenv/bin/activate
    

    Then install build dependencies:

    # sudo apt-get build-dep python-mysqldb
    

    Now you can install python-mysql

    # pip install mysql-python
    

    NOTE Ubuntu package is python-mysql*db* , python pypi package is python-mysql (without db)

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