Python 当我使用pip安装mysqlclient时,我遇到了一个错误

Python 当我使用pip安装mysqlclient时,我遇到了一个错误,python,django,terminal,pip,mysql-python,Python,Django,Terminal,Pip,Mysql Python,我正在尝试使用pip安装mysqlclient,但它一直遇到错误。 我看到一些建议告诉我要确保mysqlclient中的python版本是最新的。我已经做到了。在推送到mysqlclient master之后,我运行了install命令,但它给出了以下错误 如何修复此错误 pip install mysqlclient 错误: (base) brijesh:~ sierra$ pip install mysqlclient Collecting mysqlclient Using cach

我正在尝试使用pip安装mysqlclient,但它一直遇到错误。 我看到一些建议告诉我要确保mysqlclient中的python版本是最新的。我已经做到了。在推送到mysqlclient master之后,我运行了install命令,但它给出了以下错误

如何修复此错误

pip install mysqlclient
错误:

(base) brijesh:~ sierra$ pip install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-1.4.6.tar.gz (85 kB)
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /opt/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-install-8qoawh1_/mysqlclient/setup.py'"'"'; __file__='"'"'/private/var/folders/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-install-8qoawh1_/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/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-wheel-yu73tf06
       cwd: /private/var/folders/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-install-8qoawh1_/mysqlclient/
  Complete output (30 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating 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/_exceptions.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
  running build_ext
  building 'MySQLdb._mysql' extension
  creating build/temp.macosx-10.9-x86_64-3.7
  creating build/temp.macosx-10.9-x86_64-3.7/MySQLdb
  gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/opt/anaconda3/include -arch x86_64 -I/opt/anaconda3/include -arch x86_64 -Dversion_info=(1,4,6,'final',0) -D__version__=1.4.6 -I/usr/local/mysql/include -I/opt/anaconda3/include/python3.7m -c MySQLdb/_mysql.c -o build/temp.macosx-10.9-x86_64-3.7/MySQLdb/_mysql.o
  xcrun: error: active developer path ("/Applications/Xcode 9.1.app/Contents/Developer") does not exist
  Use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, or use `xcode-select --install` to install the standalone command line developer tools.
  See `man xcode-select` for more details.
  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
    Running setup.py install for mysqlclient ... error
    ERROR: Command errored out with exit status 1:
     command: /opt/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-install-8qoawh1_/mysqlclient/setup.py'"'"'; __file__='"'"'/private/var/folders/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-install-8qoawh1_/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/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-record-xce3nbnm/install-record.txt --single-version-externally-managed --compile --install-headers /opt/anaconda3/include/python3.7m/mysqlclient
         cwd: /private/var/folders/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-install-8qoawh1_/mysqlclient/
    Complete output (30 lines):
    running install
    running build
    running build_py
    creating build
    creating 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/_exceptions.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
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build/temp.macosx-10.9-x86_64-3.7
    creating build/temp.macosx-10.9-x86_64-3.7/MySQLdb
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/opt/anaconda3/include -arch x86_64 -I/opt/anaconda3/include -arch x86_64 -Dversion_info=(1,4,6,'final',0) -D__version__=1.4.6 -I/usr/local/mysql/include -I/opt/anaconda3/include/python3.7m -c MySQLdb/_mysql.c -o build/temp.macosx-10.9-x86_64-3.7/MySQLdb/_mysql.o
    xcrun: error: active developer path ("/Applications/Xcode 9.1.app/Contents/Developer") does not exist
    Use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, or use `xcode-select --install` to install the standalone command line developer tools.
    See `man xcode-select` for more details.
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /opt/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-install-8qoawh1_/mysqlclient/setup.py'"'"'; __file__='"'"'/private/var/folders/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-install-8qoawh1_/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/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-record-xce3nbnm/install-record.txt --single-version-externally-managed --compile --install-headers /opt/anaconda3/include/python3.7m/mysqlclient Check the logs for full command output.
这可能是一个重复的问题,来源之一是:

您似乎在使用蟒蛇,因为您的python位于/opt/anaconda3/bin/python,因此您应该更喜欢使用conda命令安装:

也就是说,您最初的问题似乎与xcode有关,您的错误建议运行xcode

xcode-select --install

我不是苹果的用户,也不太熟悉在MacOS上安装正确的开发工具。如果上面不起作用,你可能会考虑在

问我,当我体验到这是因为我有一个32位的Python版本。尝试安装64位版本的python?@Reez0那么我现在该怎么办?确保64位版本的python在您的路径上,并运行pip install mysqlclient。或者完全卸载32位版本的python,然后重试。@Reez0如何添加路径?sudo apt get install libssl dev先生,这不起作用,我遇到了问题,所以我提出了这个问题,我没有复制任何其他问题。很抱歉。你能试试这个命令吗:sudo-apt-get-install-libevent-dev,然后看看它是否能成功。
conda install mysqlclient
xcode-select --install