【问题标题】:Python pip install mysqlclientPython pip 安装 mysqlclient
【发布时间】:2019-12-21 21:17:27
【问题描述】:

所以我第一次下载了 Python 32 位,然后我下载了 python -m pip install mysqlclient.

我需要 Visual C++ 2015,但我有它们,因为我的文本编辑器是 VSCode。 我卸载了 VSCode,安装了 Visual Studio 构建工具,每当我执行 python -m pip install mysqlclient.One 时都会收到此错误,cl.exe 没有添加到我的路径中,所以我做了,但它仍然说

 error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\cl.exe' failed with exit status 2

所以我下载了windows的wheel包,正如其他一些stackoverflow答案所说。每当我运行它时,我都会得到

我尝试下载 Python 64 位下载轮子,将 cl.exe 添加到路径。

Collecting mysqlclient
  Using cached https://files.pythonhosted.org/packages/4d/38/c5f8bac9c50f3042c8f05615f84206f77f03db79781db841898fde1bb284/mysqlclient-1.4.4.tar.gz
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\Program Files (x86)\Python\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Patrik\\AppData\\Local\\Temp\\pip-install-0vmm7fdx\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\Patrik\\AppData\\Local\\Temp\\pip-install-0vmm7fdx\\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 'C:\Users\Patrik\AppData\Local\Temp\pip-wheel-o3ba369p' --python-tag cp37
       cwd: C:\Users\Patrik\AppData\Local\Temp\pip-install-0vmm7fdx\mysqlclient\
  Complete output (30 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.7
  creating build\lib.win-amd64-3.7\MySQLdb
  copying MySQLdb\__init__.py -> build\lib.win-amd64-3.7\MySQLdb
  copying MySQLdb\_exceptions.py -> build\lib.win-amd64-3.7\MySQLdb
  copying MySQLdb\compat.py -> build\lib.win-amd64-3.7\MySQLdb
  copying MySQLdb\connections.py -> build\lib.win-amd64-3.7\MySQLdb
  copying MySQLdb\converters.py -> build\lib.win-amd64-3.7\MySQLdb
  copying MySQLdb\cursors.py -> build\lib.win-amd64-3.7\MySQLdb
  copying MySQLdb\release.py -> build\lib.win-amd64-3.7\MySQLdb
  copying MySQLdb\times.py -> build\lib.win-amd64-3.7\MySQLdb
  creating build\lib.win-amd64-3.7\MySQLdb\constants
  copying MySQLdb\constants\__init__.py -> build\lib.win-amd64-3.7\MySQLdb\constants
  copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-3.7\MySQLdb\constants
  copying MySQLdb\constants\CR.py -> build\lib.win-amd64-3.7\MySQLdb\constants
  copying MySQLdb\constants\ER.py -> build\lib.win-amd64-3.7\MySQLdb\constants
  copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-3.7\MySQLdb\constants
  copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-3.7\MySQLdb\constants
  running build_ext
  building 'MySQLdb._mysql' extension
  creating build\temp.win-amd64-3.7
  creating build\temp.win-amd64-3.7\Release
  creating build\temp.win-amd64-3.7\Release\MySQLdb
  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,4,4,'final',0) -D__version__=1.4.4 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include\mariadb" "-IC:\Program Files (x86)\Python\include" "-IC:\Program Files (x86)\Python\include" /TcMySQLdb/_mysql.c /Fobuild\temp.win-amd64-3.7\Release\MySQLdb/_mysql.obj /Zl /D_CRT_SECURE_NO_WARNINGS
  _mysql.c
  MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\cl.exe' failed with exit status 2
  ----------------------------------------
  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: 'C:\Program Files (x86)\Python\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Patrik\\AppData\\Local\\Temp\\pip-install-0vmm7fdx\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\Patrik\\AppData\\Local\\Temp\\pip-install-0vmm7fdx\\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 'C:\Users\Patrik\AppData\Local\Temp\pip-record-nk0ejlkz\install-record.txt' --single-version-externally-managed --compile
         cwd: C:\Users\Patrik\AppData\Local\Temp\pip-install-0vmm7fdx\mysqlclient\
    Complete output (30 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.7
    creating build\lib.win-amd64-3.7\MySQLdb
    copying MySQLdb\__init__.py -> build\lib.win-amd64-3.7\MySQLdb
    copying MySQLdb\_exceptions.py -> build\lib.win-amd64-3.7\MySQLdb
    copying MySQLdb\compat.py -> build\lib.win-amd64-3.7\MySQLdb
    copying MySQLdb\connections.py -> build\lib.win-amd64-3.7\MySQLdb
    copying MySQLdb\converters.py -> build\lib.win-amd64-3.7\MySQLdb
    copying MySQLdb\cursors.py -> build\lib.win-amd64-3.7\MySQLdb
    copying MySQLdb\release.py -> build\lib.win-amd64-3.7\MySQLdb
    copying MySQLdb\times.py -> build\lib.win-amd64-3.7\MySQLdb
    creating build\lib.win-amd64-3.7\MySQLdb\constants
    copying MySQLdb\constants\__init__.py -> build\lib.win-amd64-3.7\MySQLdb\constants
    copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-3.7\MySQLdb\constants
    copying MySQLdb\constants\CR.py -> build\lib.win-amd64-3.7\MySQLdb\constants
    copying MySQLdb\constants\ER.py -> build\lib.win-amd64-3.7\MySQLdb\constants
    copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-3.7\MySQLdb\constants
    copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-3.7\MySQLdb\constants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build\temp.win-amd64-3.7
    creating build\temp.win-amd64-3.7\Release
    creating build\temp.win-amd64-3.7\Release\MySQLdb
    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,4,4,'final',0) -D__version__=1.4.4 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include\mariadb" "-IC:\Program Files (x86)\Python\include" "-IC:\Program Files (x86)\Python\include" /TcMySQLdb/_mysql.c /Fobuild\temp.win-amd64-3.7\Release\MySQLdb/_mysql.obj /Zl /D_CRT_SECURE_NO_WARNINGS
    _mysql.c
    MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Program Files (x86)\Python\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Patrik\\AppData\\Local\\Temp\\pip-install-0vmm7fdx\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\Patrik\\AppData\\Local\\Temp\\pip-install-0vmm7fdx\\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 'C:\Users\Patrik\AppData\Local\Temp\pip-record-nk0ejlkz\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.

它应该可以正常工作,并且包 mysqlclient 只需使用 pip 安装,因此我可以将它与 django 一起使用。

【问题讨论】:

    标签: python mysql django windows cmd


    【解决方案1】:

    当前版本 1.4.4 没有官方轮盘,当您尝试从源代码安装时遇到错误。

    由于您在 Windows 上使用 64 位 Python,您可以安装 1.4.2.post1,因为该版本有官方轮子。

    python -m pip install mysqlclient==1.4.2.post1
    

    或者,您可以从https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient 下载一个非官方的轮子,它具有适用于 Windows 上 32 位和 64 位 Python 的最新版本的轮子。除非你有特殊原因使用 32 位 Python,否则我建议你使用 64 位。

    例如,您可以下载 mysqlclient‑1.4.4‑cp37‑cp37m‑win_amd64.whl(适用于 Windows 的 Python 3.7 64 位)然后执行以下操作:

    python -m pip install mysqlclient‑1.4.4‑cp37‑cp37m‑win_amd64.whl
    

    【讨论】:

    • OH.MY.GOD。谢谢。我花了 6 个小时,没有人告诉我,它立即运行。谢谢。现在我终于可以运行数据库了。
    • 另外,不要使用 VIRTUALENV 运行“pip install ~”。使用 virtualenv,我得到了一个小时的错误。但是,全局安装明显成功。
    • @JayLim 我不确定你为什么在虚拟环境中遇到问题。也许使用python -m pip install 会奏效。一般来说,使用虚拟环境是一个好习惯,所以我不建议全局安装包。
    【解决方案2】:

    FWIW:我在 macOS 上也遇到过这个问题,错误:

    ld: library not found for -lssl
        clang: error: linker command failed with exit code 1 (use -v to see invocation)
        error: command 'xcrun' failed with exit status 1
    

    一个对我有用的解决方案(借自这个相关的post)是修复 brew 安装的 openssl 链接:

    export LDFLAGS="-L/usr/local/opt/openssl/lib"
    export CPPFLAGS="-I/usr/local/opt/openssl/include"
    

    【讨论】:

      【解决方案3】:

      我有类似的情况,我这样做了:

      sudo apt-get install python3-dev libmysqlclient-dev
      

      之后,在虚拟环境中:

      pip3 install mysqlclient
      

      那是因为,我在安装时遇到了另一个问题:

      pip3 install flask-mysqldb
      

      【讨论】:

        猜你喜欢
        • 2020-01-13
        • 2018-12-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-09-21
        • 2020-01-13
        • 2020-04-06
        • 1970-01-01
        相关资源
        最近更新 更多