pip安装MySQL-python [英] pip install MySQL-python

查看:118
本文介绍了pip安装MySQL-python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Mac OS上为Python安装MySQLdb.当我输入 pip install MySQL-python shell时,将返回以下内容:

I'm trying to install MySQLdb for Python on Mac OS. When I digit pip install MySQL-python shell returns to this:

 Collecting MySQL-python
  Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "", line 1, in 
      File "/private/var/folders/9h/2lp9kx993ygbrfk1lxr0sz500000gq/T/pip-install-7xyyBe/MySQL-python/setup.py", line 17, in 
        metadata, options = get_config()
      File "setup_posix.py", line 53, in get_config
        libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ]
      File "setup_posix.py", line 8, in dequote
        if s[0] in "\"'" and s[0] == s[-1]:
    IndexError: string index out of range

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/9h/2lp9kx993ygbrfk1lxr0sz500000gq/T/pip-install-7xyyBe/MySQL-python/

我该怎么办?我到处搜索,但找不到答案.(我已经安装了Python 2.7)

What can I do? I searched everywhere but I couldn't find an answer. (I had installed Python 2.7)

推荐答案

我更正了该错误.如果有人遇到此错误,请按照以下步骤操作:

I fixed the error. If anyone have this error just follow these steps:

  1. 首先安装mysql连接器

  1. First of all install mysql connector

简单安装mysql-connector-c

brew install mysql-connector-c

  1. 您必须修改mysql_config中的行(这是一个别名)

vim/usr/local/bin/mysql_config

vim /usr/local/bin/mysql_config

(我真诚地考虑使用文件编辑器打开mysql_config,您可以找到确切的文件夹在这里)

(I sincerely consider to open mysql_config with a file editor, you can find the exact folder here)

/usr/local/Cellar/mysql-connector-c/6.1.11/bin/

/usr/local/Cellar/mysql-connector-c/6.1.11/bin/

  1. 替换这些行.



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

应为:

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

  1. 设置环境变量

brew info openssl

brew info openssl

它会告诉您需要什么


 For compilers to find this software you may need to set:
      LDFLAGS:  -L/usr/local/opt/openssl/lib
      CPPFLAGS: -I/usr/local/opt/openssl/include
  For pkg-config to find this software you may need to set:
      PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig

  1. 然后您可以安装MySQL

pip install MySQL-python

pip install MySQL-python

  1. 您可以通过以下方法测试是否安装了MySQL:

python -c导入MySQLdb"

python -c "import MySQLdb"

希望这对您也有用!

这篇关于pip安装MySQL-python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆