pymysqlclient 提示Microsoft Visual C++ 14.0 is required问题

本文详细介绍了在Python环境中安装mysqlclient库遇到的问题及解决方案。当使用pip安装mysqlclient时,可能会遇到连接错误或构建失败的问题,文章提供了离线安装的方法,通过下载预编译的whl文件并使用pip进行本地安装,解决了Microsoft Visual C++ 14.0 缺失的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C:\Users\zhengk>pip install mysqlclient
Collecting mysqlclient
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x03B1C050>: Failed to establish a new connection: [Errno 11002] getaddrinfo failed',)': /simple/mysqlclient/
  Downloading https://files.pythonhosted.org/packages/ec/fd/83329b9d3e14f7344d1cb31f128e6dbba70c5975c9e57896815dbb1988ad/mysqlclient-1.3.13.tar.gz (90kB)
    100% |████████████████████████████████| 92kB 4.3kB/s
Building wheels for collected packages: mysqlclient
  Running setup.py bdist_wheel for mysqlclient ... error
  Complete output from command d:\software\python\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\zhengk\\AppData\\Local\\Temp\\pip-install-88poub55\\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\zhengk\AppData\Local\Temp\pip-wheel-njpn_rjk --python-tag cp36:
  d:\software\python\lib\distutils\dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
    warnings.warn(msg)
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win32-3.6
  copying _mysql_exceptions.py -> build\lib.win32-3.6
  creating build\lib.win32-3.6\MySQLdb
  copying MySQLdb\__init__.py -> build\lib.win32-3.6\MySQLdb
  copying MySQLdb\compat.py -> build\lib.win32-3.6\MySQLdb
  copying MySQLdb\connections.py -> build\lib.win32-3.6\MySQLdb
  copying MySQLdb\converters.py -> build\lib.win32-3.6\MySQLdb
  copying MySQLdb\cursors.py -> build\lib.win32-3.6\MySQLdb
  copying MySQLdb\release.py -> build\lib.win32-3.6\MySQLdb
  copying MySQLdb\times.py -> build\lib.win32-3.6\MySQLdb
  creating build\lib.win32-3.6\MySQLdb\constants
  copying MySQLdb\constants\__init__.py -> build\lib.win32-3.6\MySQLdb\constants
  copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.6\MySQLdb\constants
  copying MySQLdb\constants\CR.py -> build\lib.win32-3.6\MySQLdb\constants
  copying MySQLdb\constants\ER.py -> build\lib.win32-3.6\MySQLdb\constants
  copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.6\MySQLdb\constants
  copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.6\MySQLdb\constants
  copying MySQLdb\constants\REFRESH.py -> build\lib.win32-3.6\MySQLdb\constants
  running build_ext
  building '_mysql' extension
  error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

  ----------------------------------------
  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
    Complete output from command d:\software\python\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\zhengk\\AppData\\Local\\Temp\\pip-install-88poub55\\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\zhengk\AppData\Local\Temp\pip-record-l6ai19vs\install-record.txt --single-version-externally-managed --compile:
    d:\software\python\lib\distutils\dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
      warnings.warn(msg)
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.6
    copying _mysql_exceptions.py -> build\lib.win32-3.6
    creating build\lib.win32-3.6\MySQLdb
    copying MySQLdb\__init__.py -> build\lib.win32-3.6\MySQLdb
    copying MySQLdb\compat.py -> build\lib.win32-3.6\MySQLdb
    copying MySQLdb\connections.py -> build\lib.win32-3.6\MySQLdb
    copying MySQLdb\converters.py -> build\lib.win32-3.6\MySQLdb
    copying MySQLdb\cursors.py -> build\lib.win32-3.6\MySQLdb
    copying MySQLdb\release.py -> build\lib.win32-3.6\MySQLdb
    copying MySQLdb\times.py -> build\lib.win32-3.6\MySQLdb
    creating build\lib.win32-3.6\MySQLdb\constants
    copying MySQLdb\constants\__init__.py -> build\lib.win32-3.6\MySQLdb\constants
    copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.6\MySQLdb\constants
    copying MySQLdb\constants\CR.py -> build\lib.win32-3.6\MySQLdb\constants
    copying MySQLdb\constants\ER.py -> build\lib.win32-3.6\MySQLdb\constants
    copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.6\MySQLdb\constants
    copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.6\MySQLdb\constants
    copying MySQLdb\constants\REFRESH.py -> build\lib.win32-3.6\MySQLdb\constants
    running build_ext
    building '_mysql' extension
    error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

    ----------------------------------------
Command "d:\software\python\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\zhengk\\AppData\\Local\\Temp\\pip-install-88poub55\\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\zhengk\AppData\Local\Temp\pip-record-l6ai19vs\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\zhengk\AppData\Local\Temp\pip-install-88poub55\mysqlclient\

解决方案

这个时候直接到以下地址下载对应的库,然后离线pip install即可

https://www.lfd.uci.edu/~gohlke/pythonlibs/#pymssql

32位的下载win32,64位的下载win_amd64
cp36后面36代表python3.6
mysqlclient‑1.3.13‑cp36‑cp36m‑win32.whl
mysqlclient‑1.3.13‑cp36‑cp36m‑win_amd64.whl
这里写图片描述

cd到你下载的目录
pip install pymssql-2.1.3-cp36-cp36m-win32.whl
### 关于 'Microsoft Visual C++ 14.0 is required' 错误 在 Linux 上遇到提示 `Microsoft Visual C++ 14.0 is required` 的错误通常是由于某些依赖项未满足或者尝试运行的程序本身并非设计用于 Linux 平台。此错误通常发生在试图通过兼容层(如 Wine 或 PyInstaller 打包的应用)来运行 Windows 应用程序时。 以下是可能的原因以及解决方案: #### 原因分析 该错误表明当前环境中缺少编译器支持库或动态链接库文件,这些文件原本由 Microsoft 提供并专为 Windows 设计。然而,在 Linux 中无法直接安装 Microsoft Visual C++ Redistributable 包,因为它们仅适用于 Windows 系统[^1]。 --- #### 解决方案一:使用交叉编译工具链 如果目标是在 Linux 下开发针对 Windows 的应用程序,则可以设置一个跨平台构建环境。具体方法如下: - 安装 MinGW 工具链以模拟 Windows 编译过程。 - 使用 MSYS2 来获取最新的 GCC 和其他必要的头文件和库文件。 示例命令: ```bash sudo apt-get update && sudo apt-get install mingw-w64 ``` 对于特定版本的需求(例如 Visual C++ 14.0),可以通过配置 MinGW-W64 支持所需的 ABI 版本[^2]。 --- #### 解决方案二:借助虚拟机或容器化技术 另一种方式是利用虚拟化技术创建完整的 Windows 开发环境。这包括但不限于以下几种实现形式: - **Docker**: 创建基于 Windows Server Core 镜像的 Docker 容器; - **VirtualBox/KVM/QEMU**: 设置独立的操作系统实例专门处理此类需求; 注意,这种方法虽然功能强大但资源消耗较大,并且需要额外维护操作系统镜像及其更新频率等问题考虑进去。 --- #### 解决方案三:调整应用部署策略 如果是 Python 脚本项目引发上述警告消息的话,那么很可能是由于打包过程中嵌入了一些原生扩展模块而造成的结果。此时建议重新审视项目的依赖关系树图,确保所有第三方插件都已提供纯解释型实现或者是经过移植后的 POSIX 兼容版替代品。 另外还可以探索 Cython 进行性能优化的同时保持良好的可移植特性[^1]。 --- #### 注意事项 无论采取哪种途径解决问题之前都应该确认清楚实际业务场景下的约束条件是什么样的?比如是否有硬性规定必须保留原有执行流程不变等等因素影响最终决策方向的选择。 --- ### 示例代码片段展示如何验证是否存在缺失 DLL 文件情况 下面给出一段简单的 PowerShell 脚本来帮助识别潜在丢失的关键组件名称列表(需转换成适合 bash shell 形式的语法才能应用于 GNU/Linux 发行版当中) : ```powershell $missingDlls = @() foreach ($file in Get-ChildItem -Recurse | Where-Object { $_.Extension -eq ".exe" }) { try { $peInfo = ([System.Diagnostics.FileVersionInfo]::GetVersionInfo($file.FullName)) if (-not (Test-Path ("C:\Windows\System32\" + $peInfo.InternalName))) { $missingDlls += ,$peInfo.InternalName } } catch {} } Write-Output "Missing Dlls:" $missingDlls | Sort-Object -Unique ``` 将其改写为 Shell Script 后可用于初步排查问题所在位置。 --- 问题
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值