【问题标题】:When i use pip install mysqlclient i got error [duplicate]当我使用 pip install mysqlclient 我得到错误 [重复]
【发布时间】:2020-06-15 14:29:46
【问题描述】:

我正在尝试使用 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.

【问题讨论】:

  • 当我遇到这种情况是因为我有一个 32 位版本的 python。尝试安装 64 位版本的 python?
  • @Reez0 那我现在该怎么办?
  • 确保 64 位版本的 Python 在您的 PATH 上并运行 pip install mysqlclient。或者完全卸载32位版本的python,然后重试。
  • @Reez0 如何添加路径?

标签: python django terminal pip mysql-python


【解决方案1】:

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

conda install mysqlclient

话虽如此,您的原始问题似乎与xcode 有关,您的错误建议运行

xcode-select --install

虽然我不是苹果用户,也不太熟悉在 MacOS 上安装正确的开发工具。如果上述方法不起作用,您也可以考虑在http://apple.stackexchange.com 询问

【讨论】:

    【解决方案2】:
    sudo apt-get install libssl-dev
    
    pip install mysqlclient
    

    这可能是一个重复的问题,起源问题是: Python 3.7, Failed building wheel for MySql-Python

    【讨论】:

    • sudo apt-get install libssl-dev 先生,这不起作用,我遇到了问题,所以我提出了问题,我没有复制任何其他问题。
    • 很抱歉。试试这个命令:sudo apt-get install libevent-dev,然后看看能不能成功。
    • 不,先生,这行不通
    • 对不起,我不知道。
    猜你喜欢
    • 2021-09-21
    • 2016-05-13
    • 1970-01-01
    • 2020-07-17
    • 1970-01-01
    • 2018-10-29
    • 1970-01-01
    • 2020-07-29
    • 2019-11-06
    相关资源
    最近更新 更多