无法在MacOS上安装mysqlclient

时间:2020-05-06 17:55:47

标签: python pip openssl mysql-python mysql-connector-python

(MacOS Catalina)
首先,我整天都在解决这个问题,但是到目前为止,各种在线解决方案都没有帮助。

我正在尝试将mysqlclient安装到python virtualenv中。我在pip install -r requirements.txt所安装的requirements.txt文件中有mysqlclient以及其他一些软件包。
它无法正常工作,并且出现以下错误:

Collecting mysqlclient==1.3.12
  Using cached mysqlclient-1.3.12.tar.gz (89 kB)
    ERROR: Command errored out with exit status 1:
     command: /Users/home/Development/HyTrust/vitals_analytics/venv-vitals/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/sn/8nl8mzqx7dsf8kp382nw3ln00000gn/T/pip-install-g4m4zd_8/mysqlclient/setup.py'"'"'; __file__='"'"'/private/var/folders/sn/8nl8mzqx7dsf8kp382nw3ln00000gn/T/pip-install-g4m4zd_8/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/sn/8nl8mzqx7dsf8kp382nw3ln00000gn/T/pip-pip-egg-info-tcpsww4i
         cwd: /private/var/folders/sn/8nl8mzqx7dsf8kp382nw3ln00000gn/T/pip-install-g4m4zd_8/mysqlclient/
    Complete output (10 lines):
    /bin/sh: mysql_config: command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/sn/8nl8mzqx7dsf8kp382nw3ln00000gn/T/pip-install-g4m4zd_8/mysqlclient/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/private/var/folders/sn/8nl8mzqx7dsf8kp382nw3ln00000gn/T/pip-install-g4m4zd_8/mysqlclient/setup_posix.py", line 44, in get_config
        libs = mysql_config("libs_r")
      File "/private/var/folders/sn/8nl8mzqx7dsf8kp382nw3ln00000gn/T/pip-install-g4m4zd_8/mysqlclient/setup_posix.py", line 26, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    OSError: mysql_config not found
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

我开始关注一些已发布的解决方案,首先运行brew install mysql。执行此命令后,错误现在变为:

Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /Users/home/Development/HyTrust/vitals_analytics/venv-vitals/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/sn/8nl8mzqx7dsf8kp382nw3ln00000gn/T/pip-install-cqm_deut/mysqlclient/setup.py'"'"'; __file__='"'"'/private/var/folders/sn/8nl8mzqx7dsf8kp382nw3ln00000gn/T/pip-install-cqm_deut/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/sn/8nl8mzqx7dsf8kp382nw3ln00000gn/T/pip-wheel-xeoz18bn
       cwd: /private/var/folders/sn/8nl8mzqx7dsf8kp382nw3ln00000gn/T/pip-install-cqm_deut/mysqlclient/
  Complete output (73 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.9-x86_64-3.7
  copying _mysql_exceptions.py -> build/lib.macosx-10.9-x86_64-3.7
  creating build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/compat.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/connections.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/converters.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/cursors.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/release.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/times.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  creating build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/CR.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/ER.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  running build_ext
  building '_mysql' extension
  creating build/temp.macosx-10.9-x86_64-3.7
  gcc -DNDEBUG -g -fwrapv -O3 -Wall -I/usr/local/opt/openssl@1.1/include -Dversion_info=(1,3,12,'final',0) -D__version__=1.3.12 -I/usr/local/Cellar/mysql/8.0.19/include/mysql -I/Users/home/Development/HyTrust/vitals_analytics/venv-vitals/include -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c _mysql.c -o build/temp.macosx-10.9-x86_64-3.7/_mysql.o
  _mysql.c:252:6: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                          s = PyUnicode_AsUTF8(item);
                            ^ ~~~~~~~~~~~~~~~~~~~~~~
  _mysql.c:282:6: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                          s = PyUnicode_AsUTF8(item);
                            ^ ~~~~~~~~~~~~~~~~~~~~~~
  _mysql.c:571:3: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                  _stringsuck(ca, value, ssl);
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  _mysql.c:560:16: note: expanded from macro '_stringsuck'
          if(t){d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;}\
                 ^~~~~~~~~~~~~~~~~~~~
  _mysql.c:572:3: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                  _stringsuck(capath, value, ssl);
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  _mysql.c:560:16: note: expanded from macro '_stringsuck'
          if(t){d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;}\
                 ^~~~~~~~~~~~~~~~~~~~
  _mysql.c:573:3: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                  _stringsuck(cert, value, ssl);
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  _mysql.c:560:16: note: expanded from macro '_stringsuck'
          if(t){d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;}\
                 ^~~~~~~~~~~~~~~~~~~~
  _mysql.c:574:3: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                  _stringsuck(key, value, ssl);
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  _mysql.c:560:16: note: expanded from macro '_stringsuck'
          if(t){d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;}\
                 ^~~~~~~~~~~~~~~~~~~~
  _mysql.c:575:3: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                  _stringsuck(cipher, value, ssl);
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  _mysql.c:560:16: note: expanded from macro '_stringsuck'
          if(t){d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;}\
                 ^~~~~~~~~~~~~~~~~~~~
  _mysql.c:1894:3: error: use of undeclared identifier 'my_bool'
                  my_bool recon = reconnect;
                  ^
  _mysql.c:1895:58: error: use of undeclared identifier 'recon'
                  mysql_options(&self->connection, MYSQL_OPT_RECONNECT, &recon);
                                                                         ^
  _mysql.c:2589:8: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
          cname = PyUnicode_AsUTF8(name);
                ^ ~~~~~~~~~~~~~~~~~~~~~~
  8 warnings and 2 errors generated.
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for mysqlclient
  Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient, docutils, six, python-dateutil, jmespath, botocore, s3transfer, boto3, idna, chardet, certifi, urllib3, pycparser, cffi, cryptography, pyOpenSSL, requests, simple-salesforce, uWSGI, coverage, django-constance, django-picklefield, sqlparse, django-debug-toolbar, billiard, vine, amqp, zipp, importlib-metadata, kombu, pycurl, celery, numpy, pandas
  Attempting uninstall: mysqlclient
    Found existing installation: mysqlclient 1.4.6
    Uninstalling mysqlclient-1.4.6:
      Successfully uninstalled mysqlclient-1.4.6
    Running setup.py install for mysqlclient ... error
    ERROR: Command errored out with exit status 1:
     command: /Users/home/Development/HyTrust/vitals_analytics/venv-vitals/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/sn/8nl8mzqx7dsf8kp382nw3ln00000gn/T/pip-install-cqm_deut/mysqlclient/setup.py'"'"'; __file__='"'"'/private/var/folders/sn/8nl8mzqx7dsf8kp382nw3ln00000gn/T/pip-install-cqm_deut/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/sn/8nl8mzqx7dsf8kp382nw3ln00000gn/T/pip-record-bkyts6bw/install-record.txt --single-version-externally-managed --compile --install-headers /Users/home/Development/HyTrust/vitals_analytics/venv-vitals/include/site/python3.7/mysqlclient
         cwd: /private/var/folders/sn/8nl8mzqx7dsf8kp382nw3ln00000gn/T/pip-install-cqm_deut/mysqlclient/
    Complete output (73 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.9-x86_64-3.7
    copying _mysql_exceptions.py -> build/lib.macosx-10.9-x86_64-3.7
    creating build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/compat.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/connections.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/converters.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/release.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/times.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    creating build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.macosx-10.9-x86_64-3.7
    gcc -DNDEBUG -g -fwrapv -O3 -Wall -I/usr/local/opt/openssl@1.1/include -Dversion_info=(1,3,12,'final',0) -D__version__=1.3.12 -I/usr/local/Cellar/mysql/8.0.19/include/mysql -I/Users/home/Development/HyTrust/vitals_analytics/venv-vitals/include -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c _mysql.c -o build/temp.macosx-10.9-x86_64-3.7/_mysql.o
    _mysql.c:252:6: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                            s = PyUnicode_AsUTF8(item);
                              ^ ~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:282:6: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                            s = PyUnicode_AsUTF8(item);
                              ^ ~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:571:3: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                    _stringsuck(ca, value, ssl);
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:560:16: note: expanded from macro '_stringsuck'
            if(t){d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;}\
                   ^~~~~~~~~~~~~~~~~~~~
    _mysql.c:572:3: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                    _stringsuck(capath, value, ssl);
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:560:16: note: expanded from macro '_stringsuck'
            if(t){d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;}\
                   ^~~~~~~~~~~~~~~~~~~~
    _mysql.c:573:3: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                    _stringsuck(cert, value, ssl);
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:560:16: note: expanded from macro '_stringsuck'
            if(t){d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;}\
                   ^~~~~~~~~~~~~~~~~~~~
    _mysql.c:574:3: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                    _stringsuck(key, value, ssl);
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:560:16: note: expanded from macro '_stringsuck'
            if(t){d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;}\
                   ^~~~~~~~~~~~~~~~~~~~
    _mysql.c:575:3: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
                    _stringsuck(cipher, value, ssl);
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:560:16: note: expanded from macro '_stringsuck'
            if(t){d=PyUnicode_AsUTF8(t);ssl_keepref[n_ssl_keepref++]=t;}\
                   ^~~~~~~~~~~~~~~~~~~~
    _mysql.c:1894:3: error: use of undeclared identifier 'my_bool'
                    my_bool recon = reconnect;
                    ^
    _mysql.c:1895:58: error: use of undeclared identifier 'recon'
                    mysql_options(&self->connection, MYSQL_OPT_RECONNECT, &recon);
                                                                           ^
    _mysql.c:2589:8: warning: assigning to 'char *' from 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
            cname = PyUnicode_AsUTF8(name);
                  ^ ~~~~~~~~~~~~~~~~~~~~~~
    8 warnings and 2 errors generated.
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
  Rolling back uninstall of mysqlclient
  Moving to /Users/home/Development/HyTrust/vitals_analytics/venv-vitals/lib/python3.7/site-packages/MySQLdb/
   from /Users/home/Development/HyTrust/vitals_analytics/venv-vitals/lib/python3.7/site-packages/~ySQLdb
  Moving to /Users/home/Development/HyTrust/vitals_analytics/venv-vitals/lib/python3.7/site-packages/mysqlclient-1.4.6.dist-info/
   from /Users/home/Development/HyTrust/vitals_analytics/venv-vitals/lib/python3.7/site-packages/~ysqlclient-1.4.6.dist-info
ERROR: Command errored out with exit status 1: /Users/home/Development/HyTrust/vitals_analytics/venv-vitals/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/sn/8nl8mzqx7dsf8kp382nw3ln00000gn/T/pip-install-cqm_deut/mysqlclient/setup.py'"'"'; __file__='"'"'/private/var/folders/sn/8nl8mzqx7dsf8kp382nw3ln00000gn/T/pip-install-cqm_deut/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/sn/8nl8mzqx7dsf8kp382nw3ln00000gn/T/pip-record-bkyts6bw/install-record.txt --single-version-externally-managed --compile --install-headers /Users/home/Development/HyTrust/vitals_analytics/venv-vitals/include/site/python3.7/mysqlclient Check the logs for full command output.

奇怪的是,pip install mysqlclient现在可以正常工作了,但是pip install -r requirements.txt仍然会产生上述与mysqlclient有关的错误。

在网上有更多建议之后,我尝试了以下操作:

  1. 重新安装openssl

  2. 添加:
    export LDFLAGS="-L/usr/local/Cellar/openssl@1.1/1.1.1g/lib"
    export CPPFLAGS="-I/usr/local/Cellar/openssl@1.1/1.1.1g/include"
    给我的~/.bash_profile

  3. 将mysql的bin和openssl的bin添加到$ PATH:
    export PATH=$PATH:/usr/local/Cellar/mysql/8.0.19/bin
    export PATH=/usr/local/opt/openssl@1.1/bin:$PATH
    (在.bash_profile中)。另外,我添加了
    export LIBRARY_PATH=/usr/local/opt/openssl@1.1/lib

  4. brew install mysql-connector-c -由于某种原因,它会安装mysql-client

  5. 取消链接并重新链接mysql

  6. 创建一个新的virtualenv。

尽管人们声称其中至少有一个对他们有用,但是这些似乎都没有改变错误的输出。

“使用未声明的标识符”使我相信我缺少一些C头文件,这些文件在include中被忽略,但是我不确定为什么会发生这种情况,除非我缺少依赖项。

我缺少某种依赖吗?它是GCC错误吗?对OpenSSL,MySQL或MacOS(对Catalina而言)的最新更新是否改变了人们以前的解决方案的有效性?

如有必要,我可以提供更多详细信息。希望有人能对此有所启发。谢谢!

0 个答案:

没有答案