简体   繁体   中英

Cannot install mysqlclient in a virtualenv

I have a virtualenv named dev and I am trying to install the required dependencies. During that, I am getting the following error at mysqlclient when I am trying to install using pip install -r requirements.txt which has the requirements:

This is the Error Log for the command which I am running:

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/

Any help would be greatly appreciated.

Regards, Bharath错误截图

MySQLdb package is a wrapper of mysql C API. so it depends on OS package. and it is out of virtualenv scope. so you need to install proper mysql package from your os package manager. or you can avoid this error by using pure python connector like pymysql

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM