Pip 错误:需要 Microsoft Visual C++ 14.0
- 2024-12-05 08:37:00
- admin 原创
- 152
问题描述:
我刚刚运行了以下命令:
pip install -U steem
安装过程一切顺利,直到安装失败pycrypto
。之后我做了
pip install cryptography
命令,因为我认为是缺少包。所以我的问题是,如何steem
在没有 pycrypto-error(或另外没有 pycrypto-package)的情况下进行安装,以及如何卸载我不需要的 cryptography-Package。(我使用的是 Windows 7 和 Python 3)
Requirement already up-to-date: python-dateutil in c:/users***appdatalo
calprogramspythonpython36libsite-packages (from dateparser->maya->steem)
...
Installing collected packages: urllib3, idna, chardet, certifi, requests, pycryp
to, funcy, w3lib, voluptuous, diff-match-patch, scrypt, prettytable, appdirs, la
ngdetect, ruamel.yaml, humanize, tzlocal, regex, dateparser, pytzdata, pendulum,
maya, ecdsa, pylibscrypt, ujson, toolz, steem
Running setup.py install for pycrypto ... error
Complete output from command c:/users***appdatalocalprogramspytho
npython36python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\
***~1\\AppData\\Local\\Temp\\pip-build-k6flhu5k\\pycrypto\\setup.py';f=getattr(
tokenize, 'open', open)(__file__);code=f.read().replace('
', '
');f.close();
exec(compile(code, __file__, 'exec'))" install --record C:Users***N~1AppDat
aLocalTemppip-igpkll6u-recordinstall-record.txt --single-version-externally-
managed --compile:
running install
running build
running build_py
...
building 'Crypto.Random.OSRNG.winrandom' 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 "c:/users***appdatalocalprogramspythonpython36python.exe -u
-c "import setuptools, tokenize;__file__='C:\\Users\\***N~1\\AppData\\Local\\
Temp\\pip-build-k6flhu5k\\pycrypto\\setup.py';f=getattr(tokenize, 'open', open)(
__file__);code=f.read().replace('
', '
');f.close();exec(compile(code, __fil
e__, 'exec'))" install --record C:Users***N~1AppDataLocalTemppip-igpkll6
u-recordinstall-record.txt --single-version-externally-managed --compile" faile
d with error code 1 in C:Users***N~1AppDataLocalTemppip-build- k6flhu5kp
ycrypto\n
解决方案 1:
您需要安装 Microsoft Visual C++ 14.0 来安装 pycrypto:
错误:需要 Microsoft Visual C++ 14.0。使用“Microsoft Visual C++ Build Tools”获取: http: //landinghub.visualstudio.com/visual-cpp-build-tools
在评论中,您询问使用哪个链接。 使用指向Visual C++ 2015 Build Tools 的链接。 这将安装 Visual C++ 14.0 而无需安装 Visual Studio。
备用链接:https ://wiki.python.org/moin/WindowsCompilers#Microsoft_Visual_C.2B-.2B-_14.2_standalone:_Build_Tools_for_Visual_Studio_2019_.28x86.2C_x64.2C_ARM.2C_ARM64.29
在评论中,您询问了pycrypto
不需要安装编译器的安装方法。链接中的二进制文件似乎适用于比您使用的 Python 版本更早的版本。一个链接指向 DropBox 帐户中的二进制文件。
我不建议下载第三方提供的加密库的二进制版本。唯一能保证你获得的版本pycrypto
与你的 Python 版本兼容且没有使用任何后门的方法是从源代码构建它。
安装 Visual C++ 后,只需重新运行原始命令:
pip install -U steem
要了解各种安装选项的含义,请运行以下命令:
pip help install
该选项的帮助-U
说
-U, --upgrade Upgrade all specified packages to the newest available
version. The handling of dependencies depends on the
upgrade-strategy used.
如果您尚未steem
安装该库,则可以运行不带该选项的命令-U
。
解决方案 2:
如果您已经安装了 Visual Studio Build Tools,但仍然收到该错误,那么您可能需要“修改”您的安装以包含 Visual C++ 构建工具。
要做到这一点:
打开 Visual Studio 安装程序(如果需要,您可以在开始菜单中搜索它)。
找到Visual Studio Build Tools并点击“修改”:
勾选“Visual C++ build tools”,然后点击右下角的“修改”进行安装:
C++ 工具安装完成后,再次运行 pip 命令就可以工作了。
解决方案 3:
在搜索“需要 Microsoft Visual C++ 14.0。使用“Microsoft Visual C++ 构建工具”获取它”后,我找到了这个问题。当我尝试pip install
从具有 C++ 扩展的源发行版构建自己的 Python 包时,我在 Azure DevOps 中收到此错误。最后,我要做的就是setuptools
在调用之前升级pip install
:
pip install --upgrade setuptools
所以这里关于从源档案安装时进行更新的建议setuptools
毕竟是正确的:)。这里也给出了这个建议。
解决方案 4:
尽管我的系统中已经安装了 Visual C++ 2015 (14.0),但当我尝试安装 pymssql 时仍然出现此错误。
我通过从这里下载 pymssql 的 .whl 文件解决了这个错误。
下载后,可以通过以下命令安装:
pip install python_package.whl
希望这有帮助
解决方案 5:
作为安装 Visual C++ 的替代方法,还有一种方法是在 Conda 中安装附加包(此选项不需要管理员权限)。这对我来说很有效:
conda install libpython m2w64-toolchain -c msys2
解决方案 6:
我遇到了同样的问题。在这里找到了解决方法。
基本上只需安装这个。
shasum 输出:
3e0de8af516c15547602977db939d8c2e44fcc0b visualcppbuildtools_full.exe
md5sum输出:
MD5 (visualcppbuildtools_full.exe) = 8d4afd3b226babecaa4effb10d69eb2e
再次运行 pip 安装命令。如果一切正常,那就好了。或者你可能会像我一样遇到以下错误:
Finished generating code
LINK : fatal error LNK1158: cannot run 'rc.exe'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\_amd64\\link.exe' failed with exit status 1158
在这里找到了上述问题的修复方法:
Visual Studio 因 rc.exe 而无法构建
这基本上是说
Add this to your PATH environment variables:
C:Program Files (x86)Windows Kits8.1inx86
Copy these files:
rc.exe
rcdll.dll
From
C:Program Files (x86)Windows Kits8.1inx86
To
C:Program Files (x86)Microsoft Visual Studio 11.0VCin
它非常有效
解决方案 7:
此处更新了下载 Microsoft Visual C++ 14.0 的链接
下载
无需 Visual Studio 下载程序即可使用
解决方案 8:
Pycrypto 存在编号为CVE-2013-7459的漏洞,且该 repo 自2014 年 6 月 23 日起就不再接受 PR 。
Pycryptodome是 PyCrypto 库的替代品,它公开的 API 与旧版 PyCrypto 几乎相同,请参阅 与 PyCrypto 的兼容性。
如果您尚未安装 pycrypto,您可以使用pip install pycryptodome
安装 pycryptodome,这样您就不会遇到 Microsoft Visual C++ 14.0 问题。
解决方案 9:
针对此错误我遵循三个步骤:
已安装 C++ 构建工具
pip 安装--升级安装工具
尝试使用 conda 安装,conda 可能有编译版本,不需要构建工具
解决方案 10:
这里其他人提出的解决方案对我都不起作用。
因此,就我而言,我必须从我的计算机上卸载所有旧版本的 Microsoft Visual C++ Redistributable:
只剩下最新的一个(就我而言是 2015-2022)!
卸载后我运行了这个命令:
pip install <your_lib_name>
此后一切都很顺利。
解决方案 11:
在 Windows 上,我强烈建议安装最新版本的 Visual Studio Community。它是免费的,如果你只安装,你可能会错过一些构建工具,所以你可以轻松地通过而不是vc_redist
安装包,这节省了大量时间。pip
`wheel`
解决方案 12:
我要在这里添加另一个答案,因为我在这个问题上花了几个小时才最终弄清楚了原因,但这非常违反直觉。
当我尝试安装 python 依赖项时,我总是收到“需要 Microsoft Visual C++ 14.0。使用“Microsoft Visual C++ 构建工具”获取它:http://landinghub.visualstudio.com/visual-cpp-build-tools”。无论我重新安装多少次,错误仍然存在。
经过几个小时的调试,问题最终是它没有被添加到我的 PATH 中。显然,对于我路径上的所有内容,添加它将使其达到 2050 个字符,而 Windows 将其限制为 2048 个字符。我猜安装程序只是默默地失败了,因此没有迹象表明。
找到构建工具的路径(我的是 C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx86 ),并将其附加到您的路径。
如果您遇到与我相同的问题,则需要通过删除此处的其他元素来缩短路径。我有几个旧的 Python 版本,我可以删除它们以达到字符数限制。
解决方案 13:
由于这些答案都不适合我,所以以下是我遇到的情况。希望这对其他人有帮助。
问题
我在安装和运行时遇到错误pandas
,例如:
pip install pandas==1.3.4
会导致:
...
building 'pandas._libs.algos' extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pandas
Failed to build pandas
ERROR: Could not build wheels for pandas, which is required to install pyproject.toml-based projects
解决方案
首先,从错误消息中提到的 URL下载Visual Studio 安装程序。
安装这两个包(总共约 7.5GB):
使用 C++ 进行桌面开发
.NET 桌面开发
(抱歉,我的机器是德语的,但图标应该匹配):)
完成后,无需打开新终端以使更改生效。只需重复相同的pip install
命令即可,这次应该会成功。
解决方案 14:
尝试这样做:
py -m pip install pipwin
py -m pipwin install PyAudio
解决方案 15:
杀手级解决方案:安装nodejs
并勾选选项install chocolatey and other necessary tools...
,它将安装设置开发环境所需的工具。