python mysql use some pit

Note: If you are using a python3.x, go directly to the fourth question

The first problem encountered

  • Normally, the implementation of direct pip installation is possible, but it happens more unique MySQL-python

pip install MySQL-python
  • An error
_mysql.c:44:10: fatal error: 'my_config.h' file not found
    #include "my_config.h"
             ^~~~~~~~~~~~~
    1 error generated.
    error: command 'cc' failed with exit status 1

Solve the first problem

  • carried outbrew install mysql-connector-c

brew install mysql-connector-c
  • If this step is done directly, it can continue pip install MySQL-python, and it should be successful
  • But I failed to perform this step

The second problem encountered

    • brew install mysql-connector-cAn error

Error: Cannot install mysql-connector-c because conflicting formulae are installed.
  mysql: because both install MySQL client libraries

Please `brew unlink mysql` before continuing.

Solve the second problem

  • According to being given a presentation,brew unlink mysql
  • What did not happen accidentally, finished, continuebrew install mysql-connector-c
  • 'Mysql-connector-c' successful installation
  • Execution brew link --overwrite mysql, reconnect mysql (I did not do this step)
  • Then perform pip install MySQL-python, if successful, to get
  • Amazingly, I failed again in this step

A third problem encountered

  • After completed the above steps, executed pip install MySQL-python, given

Collecting mysql
  Downloading https://files.pythonhosted.org/packages/06/ef/c4efbf2a51fb46aba9be03a973638d9539c9ca10a5259b2cbb1a66133b2e/mysql-0.0.1.tar.gz
Collecting MySQL-python (from mysql)
  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 "<string>", line 1, in <module>
      File "/private/var/folders/zn/t8xxx4m149s9jqp1810ndrz80000gn/T/pip-install-oHMKPE/MySQL-python/setup.py", line 17, in <module>
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

The third problem solving

    • Mysql modify the configuration file mysql_configbefore modifying cp remember about 
      execution mysql_config, look at the path
    • Open the file vim mysql_config, find libs="$libs -l ", insteadlibs="$libs -lmysqlclient -lssl -lcrypto "

= libs " -L $ pkglibdir " 
# libs = "$ libs the -l" # original 
libs = " $ libs -lmysqlclient -lssl -lcrypto "       # after the change 
embedded_libs = " -L $ pkglibdir " 
embedded_libs = " $ embedded_libs - L "
  • do it againpip install MySQL-python
  • Finally succeeded! congratulations! congratulations!
  • Carefully try, import MySQLdbreally successful

The fourth problem found


 

  • When started, and found himself with a python2.xcircumstances, replaced python3.xcontinue to use
  • The import MySQLdbtime has gone wrong,ModuleNotFoundError: No module named 'MySQLdb'
  • Try to use the pip3 install MySQL-pythoninstallation again, the error

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 "<string>", line 1, in <module>
      File "/private/var/folders/07/v8slhf9x5zsbbd8_9cd5ztnh0000gp/T/pip-install-oh_74ez5/MySQL-python/setup.py", line 13, in <module>
from setup_posix import get_config
      File "/private/var/folders/07/v8slhf9x5zsbbd8_9cd5ztnh0000gp/T/pip-install-oh_74ez5/MySQL-python/setup_posix.py", line 2, in <module>
from ConfigParser import SafeConfigParser
    ModuleNotFoundError: No module named 'ConfigParser'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/07/v8slhf9x5zsbbd8_9cd5ztnh0000gp/T/pip-install-oh_74ez5/MySQL-python/

The fourth problem solving

  • I found the reason, feel waves of silent

In Python 3, ConfigParser has been renamed to configparser for PEP 8 compliance. It looks like the package you are installing does not support Python 3.
In Python3 in, ConfigParser order to comply with PEP8 specification, has been renamed configparser. It looks like you are installing the package does not support Python3.

    • Because they do not support python3, recommended pip install pymysql, not so much the installation routine
    • In fact, we found a solution (not tested, I do not know right, simply record it)

      • A method, as modified six modules

try:
    import configparser
except:
    from six.moves import configparser

Method Two

cp /usr/local/lib/python3.7/configparser.py /usr/local/lib/python3.7/ConfigParser.py

Finally, the exchange group 887,934,385, to explore technology to enhance learning.

Guess you like

Origin www.cnblogs.com/pypypy/p/12026108.html