解决python2项目MySQLDB依赖问题

复制代码



因为新项目要引用MySQLdb,而且是python2,之前自己写机器学习的项目都是python3,搞了一个早上,卡在import MySQLdb上了

运行

pip2 install mysqlclient复制代码

告诉我

dflags=''
      File "<string>", line 1, in <module>
      File "/private/var/folders/l3/hc2gmq15269bw3j7258p2tgc0000gn/T/pip-install-9KeT9n/mysqlclient/setup.py", line 16, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 51, in get_config
        libs = mysql_config("libs")
      File "setup_posix.py", line 29, in mysql_config
        raise EnvironmentError("%s not found" % (_mysql_config_path,))
    EnvironmentError: mysql_config not found

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/l3/hc2gmq15269bw3j7258p2tgc0000gn/T/pip-install-9KeT9n/mysqlclient/复制代码

试了好多办法

终于在

stackoverflow.com/questions/5…

找到了完美解决方案



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

感觉有点坑啊


转载于:https://juejin.im/post/5d007e21f265da1b897ac864

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值