zoukankan      html  css  js  c++  java
  • Mac上安装MySQL-python遇到的问题和解决方法

    背景

    原本在我的电脑上是安装了MySQL-python模块的,后来我把电脑升级到了Big Sur,这下可能导致有些东西不兼容了。

    遇到的报错

    ╰─$ pip install MySQL-python==1.2.5                                                                                                                                              1 ↵
    DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
    Collecting MySQL-python==1.2.5
      Using cached MySQL-python-1.2.5.zip (108 kB)
    Building wheels for collected packages: MySQL-python
      Building wheel for MySQL-python (setup.py) ... error
      ERROR: Command errored out with exit status 1:
       command: /Users/bryan/bitbucket/ops-ec2-center/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/kk/t4lln2zx3ls8k54bqnpy0gw00000gn/T/pip-install-2Qn5j9/mysql-python/setup.py'"'"'; __file__='"'"'/private/var/folders/kk/t4lln2zx3ls8k54bqnpy0gw00000gn/T/pip-install-2Qn5j9/mysql-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'
    '"'"', '"'"'
    '"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/kk/t4lln2zx3ls8k54bqnpy0gw00000gn/T/pip-wheel-S5mf2n
           cwd: /private/var/folders/kk/t4lln2zx3ls8k54bqnpy0gw00000gn/T/pip-install-2Qn5j9/mysql-python/
      Complete output (27 lines):
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-11.1-x86_64-2.7
      copying _mysql_exceptions.py -> build/lib.macosx-11.1-x86_64-2.7
      creating build/lib.macosx-11.1-x86_64-2.7/MySQLdb
      copying MySQLdb/__init__.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb
      copying MySQLdb/converters.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb
      copying MySQLdb/connections.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb
      copying MySQLdb/cursors.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb
      copying MySQLdb/release.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb
      copying MySQLdb/times.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb
      creating build/lib.macosx-11.1-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/__init__.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/CR.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/ER.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/FLAG.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb/constants
      running build_ext
      building '_mysql' extension
      creating build/temp.macosx-11.1-x86_64-2.7
      cc -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -iwithsysroot /usr/local/libressl/include -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/opt/mysql-client/include/mysql -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-11.1-x86_64-2.7/_mysql.o
      clang: error: invalid version number in 'MACOSX_DEPLOYMENT_TARGET=11.1'
      error: command 'cc' failed with exit status 1
      ----------------------------------------
      ERROR: Failed building wheel for MySQL-python
    
    

    查找资料说可能是xcode的命令行工具不兼容导致的,所以我把老的目录备份并重新安装了一下

    cd /Library/Developer
    mv CommandLineTools CommandLineTools.bakup
    
    xcode-select --install
    

    安装完后报了另一个错

    ╰─$ pip install MySQL-python==1.2.5       
    DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
    Collecting MySQL-python==1.2.5
      Using cached MySQL-python-1.2.5.zip (108 kB)
    Building wheels for collected packages: MySQL-python
      Building wheel for MySQL-python (setup.py) ... error
      ERROR: Command errored out with exit status 1:
       command: /Users/bryan/bitbucket/ops-ec2-center/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/kk/t4lln2zx3ls8k54bqnpy0gw00000gn/T/pip-install-EQ1alF/mysql-python/setup.py'"'"'; __file__='"'"'/private/var/folders/kk/t4lln2zx3ls8k54bqnpy0gw00000gn/T/pip-install-EQ1alF/mysql-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'
    '"'"', '"'"'
    '"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/kk/t4lln2zx3ls8k54bqnpy0gw00000gn/T/pip-wheel-04YS2E
           cwd: /private/var/folders/kk/t4lln2zx3ls8k54bqnpy0gw00000gn/T/pip-install-EQ1alF/mysql-python/
      Complete output (79 lines):
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-11.1-x86_64-2.7
      copying _mysql_exceptions.py -> build/lib.macosx-11.1-x86_64-2.7
      creating build/lib.macosx-11.1-x86_64-2.7/MySQLdb
      copying MySQLdb/__init__.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb
      copying MySQLdb/converters.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb
      copying MySQLdb/connections.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb
      copying MySQLdb/cursors.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb
      copying MySQLdb/release.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb
      copying MySQLdb/times.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb
      creating build/lib.macosx-11.1-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/__init__.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/CR.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/ER.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/FLAG.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-11.1-x86_64-2.7/MySQLdb/constants
      running build_ext
      building '_mysql' extension
      creating build/temp.macosx-11.1-x86_64-2.7
      cc -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -iwithsysroot /usr/local/libressl/include -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mysql@5.7/5.7.32/include/mysql -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-11.1-x86_64-2.7/_mysql.o
      _mysql.c:287:14: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
                      cmd_argc = PySequence_Size(cmd_args);
                               ~ ^~~~~~~~~~~~~~~~~~~~~~~~~
      _mysql.c:317:12: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
                      groupc = PySequence_Size(groups);
                             ~ ^~~~~~~~~~~~~~~~~~~~~~~
      _mysql.c:470:14: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
                              int j, n2=PySequence_Size(fun);
                                     ~~ ^~~~~~~~~~~~~~~~~~~~
      _mysql.c:1127:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                      len = mysql_real_escape_string(&(self->connection), out, in, size);
                          ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      _mysql.c:1129:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                      len = mysql_escape_string(out, in, size);
                          ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      _mysql.c:1168:9: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
              size = PyString_GET_SIZE(s);
                   ~ ^~~~~~~~~~~~~~~~~~~~
      /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/stringobject.h:92:32: note: expanded from macro 'PyString_GET_SIZE'
      #define PyString_GET_SIZE(op)  Py_SIZE(op)
                                     ^~~~~~~~~~~
      /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/object.h:116:56: note: expanded from macro 'Py_SIZE'
      #define Py_SIZE(ob)             (((PyVarObject*)(ob))->ob_size)
                                       ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
      _mysql.c:1178:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                      len = mysql_real_escape_string(&(self->connection), out+1, in, size);
                          ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      _mysql.c:1180:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                      len = mysql_escape_string(out+1, in, size);
                          ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      _mysql.c:1274:11: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
              if ((n = PyObject_Length(o)) == -1) goto error;
                     ~ ^~~~~~~~~~~~~~~~~~
      /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/abstract.h:434:25: note: expanded from macro 'PyObject_Length'
      #define PyObject_Length PyObject_Size
                              ^
      _mysql.c:1466:10: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                              len = strlen(buf);
                                  ~ ^~~~~~~~~~~
      _mysql.c:1468:10: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                              len = strlen(buf);
                                  ~ ^~~~~~~~~~~
      _mysql.c:1504:11: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                                      len = strlen(buf);
                                          ~ ^~~~~~~~~~~
      _mysql.c:1506:11: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                                      len = strlen(buf);
                                          ~ ^~~~~~~~~~~
      13 warnings generated.
      cc -bundle -undefined dynamic_lookup -Wl,-F. -L/AppleInternal/BuildRoot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.Internal.sdk/usr/local/libressl/lib build/temp.macosx-11.1-x86_64-2.7/_mysql.o -L/usr/local/Cellar/mysql@5.7/5.7.32/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-11.1-x86_64-2.7/_mysql.so
      ld: warning: directory not found for option '-L/AppleInternal/BuildRoot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.Internal.sdk/usr/local/libressl/lib'
      ld: library not found for -lssl
      clang: error: linker command failed with exit code 1 (use -v to see invocation)
      error: command 'cc' failed with exit status 1
      ----------------------------------------
    
    

    这里看起来又和ssl有关,于是我把ssl重新装了一下,又设置了一下环境变量就可以正常安装了

    brew install openssl
    export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
    
  • 相关阅读:
    八十五:redis之redis的事物、发布和订阅操作 (2019-11-18 22:54)
    八十四:redis之redis的集合、哈希操作
    八十三:redis之redis的字符串、过期时间、列表操作
    八十三:redis之redis的使用场景和安装
    八十二:memcached之python操作memcached
    八十一:memcached之telnet操作memcached
    八十:memcached之安装与参数
    MySQL篇之Navicat可视化工具
    MySQL数据库篇之多表查询
    MySQL数据库篇之单表查询
  • 原文地址:https://www.cnblogs.com/alexguome/p/14310355.html
Copyright © 2011-2022 走看看