无法在virtualenv中安装mysqlclient

时间:2019-03-07 19:20:01

标签: python mysql virtualenv

我有一个名为dev的virtualenv,我正在尝试安装所需的依赖项。在此期间,当我尝试使用具有要求的pip install -r requirements.txt进行安装时,在mysqlclient上出现以下错误:

这是我正在运行的命令的错误日志:

Collecting slack-log-handler==0.2.2 (from -r requirements.txt (line 16))
Collecting SQLAlchemy==1.0.15 (from -r requirements.txt (line 17))
Requirement already satisfied: Werkzeug==0.11.11 in /Users/bharathv/Desktop/Work/Customer_API/dev/lib/python2.7/site-packages (from -r requirements.txt (line 18)) (0.11.11)
Collecting pendulum==2.0.4 (from -r requirements.txt (line 19))
Collecting typing<4.0,>=3.6; python_version < "3.5" (from pendulum==2.0.4->-r requirements.txt (line 19))
  Using cached https://files.pythonhosted.org/packages/cc/3e/29f92b7aeda5b078c86d14f550bf85cff809042e3429ace7af6193c3bc9f/typing-3.6.6-py2-none-any.whl
Collecting pytzdata>=2018.3 (from pendulum==2.0.4->-r requirements.txt (line 19))
  Using cached https://files.pythonhosted.org/packages/89/02/a3a1cef5074c28157df63846d05aa893f007a92f6bafec0d61cae36bf69d/pytzdata-2018.9-py2.py3-none-any.whl
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (setup.py) ... error
  Complete output from command /Users/bharathv/Desktop/Work/Customer_API/dev/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/dc/dqq29fh52nq9nppk0rd0kdg40000gp/T/pip-install-pemYYE/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/dc/dqq29fh52nq9nppk0rd0kdg40000gp/T/pip-wheel-P7vfx2 --python-tag cp27:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.14-x86_64-2.7
  copying _mysql_exceptions.py -> build/lib.macosx-10.14-x86_64-2.7
  creating build/lib.macosx-10.14-x86_64-2.7/MySQLdb
  copying MySQLdb/__init__.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb
  copying MySQLdb/compat.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb
  copying MySQLdb/converters.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb
  copying MySQLdb/connections.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb
  copying MySQLdb/cursors.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb
  copying MySQLdb/release.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb
  copying MySQLdb/times.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb
  creating build/lib.macosx-10.14-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/CR.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/ER.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb/constants
  copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb/constants
  running build_ext
  building '_mysql' extension
  creating build/temp.macosx-10.14-x86_64-2.7
  clang -fno-strict-aliasing -fno-common -dynamic -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Dversion_info=(1,3,7,'final',1) -D__version__=1.3.7 -I/usr/local/Cellar/mysql/8.0.15/include/mysql -I/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.14-x86_64-2.7/_mysql.o
  _mysql.c:29:10: fatal error: 'my_config.h' file not found
  #include "my_config.h"
           ^~~~~~~~~~~~~
  1 error generated.
  error: command 'clang' failed with exit status 1

  ----------------------------------------
  Failed building wheel for mysqlclient
  Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient, Flask-MySQLdb, pytz, Flask-RESTful, mysql, requests, slack-log-handler, SQLAlchemy, typing, pytzdata, pendulum
  Running setup.py install for mysqlclient ... error
    Complete output from command /Users/bharathv/Desktop/Work/Customer_API/dev/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/dc/dqq29fh52nq9nppk0rd0kdg40000gp/T/pip-install-pemYYE/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/dc/dqq29fh52nq9nppk0rd0kdg40000gp/T/pip-record-y_LFeb/install-record.txt --single-version-externally-managed --compile --install-headers /Users/bharathv/Desktop/Work/Customer_API/dev/bin/../include/site/python2.7/mysqlclient:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.14-x86_64-2.7
    copying _mysql_exceptions.py -> build/lib.macosx-10.14-x86_64-2.7
    creating build/lib.macosx-10.14-x86_64-2.7/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb
    copying MySQLdb/compat.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb
    copying MySQLdb/converters.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb
    copying MySQLdb/connections.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb
    copying MySQLdb/release.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb
    copying MySQLdb/times.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb
    creating build/lib.macosx-10.14-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.14-x86_64-2.7/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.macosx-10.14-x86_64-2.7
    clang -fno-strict-aliasing -fno-common -dynamic -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Dversion_info=(1,3,7,'final',1) -D__version__=1.3.7 -I/usr/local/Cellar/mysql/8.0.15/include/mysql -I/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.14-x86_64-2.7/_mysql.o
    _mysql.c:29:10: fatal error: 'my_config.h' file not found
    #include "my_config.h"
             ^~~~~~~~~~~~~
    1 error generated.
    error: command 'clang' failed with exit status 1

    ----------------------------------------
Command "/Users/bharathv/Desktop/Work/Customer_API/dev/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/dc/dqq29fh52nq9nppk0rd0kdg40000gp/T/pip-install-pemYYE/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/dc/dqq29fh52nq9nppk0rd0kdg40000gp/T/pip-record-y_LFeb/install-record.txt --single-version-externally-managed --compile --install-headers /Users/bharathv/Desktop/Work/Customer_API/dev/bin/../include/site/python2.7/mysqlclient" failed with error code 1 in /private/var/folders/dc/dqq29fh52nq9nppk0rd0kdg40000gp/T/pip-install-pemYYE/mysqlclient/

任何帮助将不胜感激。

关于, 巴拉特error screenshot

1 个答案:

答案 0 :(得分:0)

MySQLdb软件包是mysql C API的包装。因此取决于OS软件包。并且它不在virtualenv范围内。 因此,您需要从os软件包管理器中安装正确的mysql软件包。 或者您可以使用pymysql

这样的纯python连接器来避免此错误