“OSError: mysql_config not found” when trying to “pip install mysqlclient” - Django

戏子无情 提交于 2019-12-02 07:21:56

问题


I'm relatively new to Django, and Web Development in general.

I am trying to

pip install mysqlclient

in my

virtualenv -p python3

to hook up Django 2.0 to mySQL. However, I'm getting this error:

Collecting mysqlclient
Using cached mysqlclient-1.3.12.tar.gz
Complete output from command python setup.py egg_info:
/bin/sh: mysql_config: command not found
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/private/var/folders/43/md5vpqrx0mx8627sq04slbz00000gn/T/pip-build-l8ea3vja/mysqlclient/setup.py", line 17, in <module>
    metadata, options = get_config()
  File "/private/var/folders/43/md5vpqrx0mx8627sq04slbz00000gn/T/pip-build-l8ea3vja/mysqlclient/setup_posix.py", line 44, in get_config
    libs = mysql_config("libs_r")
  File "/private/var/folders/43/md5vpqrx0mx8627sq04slbz00000gn/T/pip-build-l8ea3vja/mysqlclient/setup_posix.py", line 26, in mysql_config
    raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: mysql_config not found

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/43/md5vpqrx0mx8627sq04slbz00000gn/T/pip-build-l8ea3vja/mysqlclient/

I have looked around for answers for hours, and yes, I have checked out this and this but nothing seems to be working.

Any help would be much appreciated!


回答1:


You should start with cloning the mysqlclient repo:

git clone https://github.com/PyMySQL/mysqlclient-python

Then you will have to get mysql-connector-c. You can get it by doing:

brew install mysql-connector-c

Then open /usr/local/bin/mysql_config in a text editor.

From the Github issue:

There are lines in mysql_config like following:

# Create options 
libs="-L$pkglibdir"
libs="$libs -l "

It should be:

#Create options 
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"

Save that file and change back to the directory where you downloaded the repo. Now open site.cfg file. uncomment the line (remove the #)

#mysql_config = /usr/local/bin/mysql_config

Save that and run:

python3 setup.py install



回答2:


the python package "mysqlclient" is depended on C system library to drive mysql connect,if you on ubuntu 16.4, just do as below:

sudo apt-get install libmysqlclient-dev
sudo pip install mysqlclient


来源:https://stackoverflow.com/questions/47870628/oserror-mysql-config-not-found-when-trying-to-pip-install-mysqlclient-dja

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!