pip install MySQL-python

為{幸葍}努か 提交于 2021-01-27 17:26:29

问题


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/

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


回答1:


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

  1. First of all install mysql connector

    brew install mysql-connector-c

    1. You have to modify lines in mysql_config (this is an alias)

    vim /usr/local/bin/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/

    1. Replace these lines.
    
      # Create options 
      libs="-L$pkglibdir"
      libs="$libs -l "
    

    should be:

      
      # Create options 
      libs="-L$pkglibdir"
      libs="$libs -lmysqlclient -lssl -lcrypto"
    
    
    1. Set environment variable

    brew info openssl

    it would tell what’s needed

     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. Then you can install MySQL

    pip install MySQL-python

    1. You can test if MySQL is installed with this:

    python -c "import MySQLdb"

    Hope this works also for you!



来源:https://stackoverflow.com/questions/51123044/pip-install-mysql-python

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