Installing MySQL-python causes command 'clang' failed with exit status 1 on Mac OS 10.13.15

不羁岁月 提交于 2019-12-02 14:44:55

I just resolved this exact issue when running Ansible's mysql_user module. The answer here helped tip me off to a solution. I also needed MySQL-python from pip, which also broke in this process, so I've added the extra steps.

Steps to resolve:

  1. brew unlink mysql # only if installed, causes the next step to fail
  2. brew install mysql-connector-c
  3. locate mysql_config file with which (mysql_config)
  4. edit the mysql_config file, under # Create options change this:

    libs="$libs -l "

    to this:

    libs="$libs -lmysqlclient -lssl -lcrypto"

    if using vim, :wq! to save the read-only file

  5. Now the install should run successfully

    pip install mysqlclient

  6. Adding this separately, as it's similar but not directly related to the initial question

    pip install MySQL-python

  7. Fix mysql brew formula, if it was unlinked in the first step.

    brew unlink mysql-connector-c

    brew link mysql

I know maybe the former answers can solve the problem already. But I'm still sharing below solution. If you don't want to brew install any extra things, you can try this solution.

I think the issue happens in many situations, mainly related to the installation of the pip packages about MySQL. In my case, I bumped into this issue when trying to install mysqlclient for Django.

This solution should work when you've installed MySQL with dmg downloaded from their official site.

In that case, you may find mysql_config in /usr/local/mysql/bin

If so, add export PATH="/usr/local/mysql/bin:${PATH}" in ~/.bash_profile, this would add the bin folder of mysql into the PATH, or you can say environment variable. Please note that mysql maybe in detail with your mysql version. In my case, the path is /usr/local/mysql-8.0.12-macos10.13-x86_64/bin.

Save and close the file, then source ~/.bash_profile to enable the change.

Try to install the pip package about MySQL again.

If still not working, a restart is preferred.

I solved this issue by setting xcode-select to use non-XCode command line tools, as shown in the below answer. I had a related clang error which led me to this answer.

sudo xcode-select --switch /Library/Developer/CommandLineTools

https://stackoverflow.com/a/30902106/11614142

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