我正在使用新的MacOS High Sierra 10.13.5。
我首先使用Homebrew安装了python3:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install python
然后,我从github克隆了我的python项目存储库,该存储库具有一个require.txt文件,其内容如下:
mysqlclient==1.3.10
然后我创建了一个虚拟环境并运行了pip安装:
python3 -m venv venv
pip install -r api/requirements.txt
然后出现以下错误:
...
...
Installing collected packages: six, python-dateutil, aniso8601,
appdirs, jmespath, docutils, botocore, s3transfer, boto3, click, Werkzeug, itsdangerous, MarkupSafe, Jinja2, Flask, Flask-Cors, blinker, Flask-Mail, jsonschema, pytz, flask-restplus, Flask-Script, SQLAlchemy, Flask-SQLAlchemy, Flask-SQLAlchemy-Session, Mako, python-editor, alembic, Flask-Migrate, PyJWT, Flask-JWT-Simple, idna, pycparser, cffi, asn1crypto, cryptography, chardet, certifi, urllib3, requests, nexmo, pyparsing, packaging, Pillow, phonenumbers, numpy, timezonefinder, decorator, ratelim, geocoder, SQLAlchemy-Utils, mysqlclient, pycrypto, simple-crypt, suds-jurko, Salesforce-FuelSDK, schedule, python-utils, progressbar2, timeago
Running setup.py install for aniso8601 ... done
Running setup.py install for itsdangerous ... done
Running setup.py install for MarkupSafe ... done
Running setup.py install for blinker ... done
Running setup.py install for Flask-Mail ... done
Running setup.py install for Flask-Script ... done
Running setup.py install for SQLAlchemy ... done
Running setup.py install for Flask-SQLAlchemy-Session ... done
Running setup.py install for Mako ... done
Running setup.py install for python-editor ... done
Running setup.py install for Flask-JWT-Simple ... done
Running setup.py install for pycparser ... done
Running setup.py install for geocoder ... done
Running setup.py install for SQLAlchemy-Utils ... done
Running setup.py install for mysqlclient ... error
Complete output from command /Users/mvi/mvi/server/venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/private/var/folders/zh/p8bfpbd166758zz6vj60jd100000gn/T/pip-install-vls9kk27/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/zh/p8bfpbd166758zz6vj60jd100000gn/T/pip-record-6eq5p42p/install-record.txt --single-version-externally-managed --compile --install-headers /Users/mvi/mvi/server/venv/include/site/python3.7/mysqlclient:
running install
running build
running build_py
creating build
creating build/lib.macosx-10.13-x86_64-3.7
copying _mysql_exceptions.py -> build/lib.macosx-10.13-x86_64-3.7
creating build/lib.macosx-10.13-x86_64-3.7/MySQLdb
copying MySQLdb/__init__.py -> build/lib.macosx-10.13-x86_64-3.7/MySQLdb
copying MySQLdb/compat.py -> build/lib.macosx-10.13-x86_64-3.7/MySQLdb
copying MySQLdb/connections.py -> build/lib.macosx-10.13-x86_64-3.7/MySQLdb
copying MySQLdb/converters.py -> build/lib.macosx-10.13-x86_64-3.7/MySQLdb
copying MySQLdb/cursors.py -> build/lib.macosx-10.13-x86_64-3.7/MySQLdb
copying MySQLdb/release.py -> build/lib.macosx-10.13-x86_64-3.7/MySQLdb
copying MySQLdb/times.py -> build/lib.macosx-10.13-x86_64-3.7/MySQLdb
creating build/lib.macosx-10.13-x86_64-3.7/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.13-x86_64-3.7/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.13-x86_64-3.7/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.macosx-10.13-x86_64-3.7/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.macosx-10.13-x86_64-3.7/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.13-x86_64-3.7/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.13-x86_64-3.7/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.13-x86_64-3.7/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.macosx-10.13-x86_64-3.7
clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Dversion_info=(1,3,10,'final',0) -D__version__=1.3.10 -I/usr/local/mysql/include -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/Users/mvi/mvi/server/venv/include -I/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c _mysql.c -o build/temp.macosx-10.13-x86_64-3.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/mvi/mvi/server/venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/private/var/folders/zh/p8bfpbd166758zz6vj60jd100000gn/T/pip-install-vls9kk27/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/zh/p8bfpbd166758zz6vj60jd100000gn/T/pip-record-6eq5p42p/install-record.txt --single-version-externally-managed --compile --install-headers /Users/mvi/mvi/server/venv/include/site/python3.7/mysqlclient" failed with error code 1 in /private/var/folders/zh/p8bfpbd166758zz6vj60jd100000gn/T/pip-install-vls9kk27/mysqlclient/
You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
在我没有问题的旧Macbook pro上。 在那本Macbook上,我有使用GCC 4.2.1的python 3.6.5。 在这个新的Macbook上,我有使用lang 9.1.0的python 3.7 (venv)$蟒蛇 Python 3.7.0(默认,2018年8月22日,15:22:33) 达尔文[Clang 9.1.0(clang-902.0.39.2)]
这篇文章是我唯一能找到的相关内容,但似乎并没有太大帮助...
https://medium.com/@MrWeeble/homebrew-on-mac-and-pythons-mysqlclient-ea44fa300e70
任何调试的想法将不胜感激。谢谢。
答案 0 :(得分:0)
您需要MySQL客户端库及其相关的标头。
这些在例如是Brew中的MariaDB(MySQL fork)软件包,因此brew install mariadb
应该可以解决问题。