【问题标题】:Microsoft Windows Python-3.6 PyCrypto installation errorMicrosoft Windows Python-3.6 PyCrypto 安装错误
【发布时间】:2017-06-10 03:24:24
【问题描述】:

pip install pycrypto 在 python3.5.2 上工作正常,但在 python3.6 上失败并出现以下错误:

inttypes.h(26):错误 C2061:语法错误:标识符“intmax_t”

【问题讨论】:

    标签: windows visual-studio pycrypto python-3.6


    【解决方案1】:

    Python安装目录下的include\pyport.h文件不再有#include 。这使得 intmax_t 未定义。

    Microsoft VC 编译器的一种解决方法是通过操作系统环境变量 CL 强制包含 stdint.h

    1. 打开命令提示符
    2. 通过运行 vcvars*.bat 设置 VC 环境(根据 VC 版本和架构选择文件名)
    3. 设置 CL=-FI"Full-Path\stdint.h"(为环境使用 Full-Path 的实际值)
    4. pip install pycrypto

    【讨论】:

    • 为什么没有将它修补到 Windows Python 发行版中?作为记录,我能够使用 vcvarsall.bat C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat
    • 该问题已在github.com/dlitz/pycrypto/issues/221 报告。问题出在 pycrypto 本身,它提供了一个不完整的stdint.h,我已经添加了对该错误报告所需修复的解释。
    • 对我来说,步骤 1+2 可以缩短为:从开始菜单,运行“Visual C++ 2015 x86 Native Build Tools Command Prompt”
    • 如果你使用 VS 2017 构建它,标题位置应该修改如下:set CL=-FI"%VCINSTALLDIR%\Tools\MSVC\ 14.16.27023\include\stdint.h - 当然 14.16.27023 数字取决于 VS 版本,我的是 15.9。
    • 这适用于我在 Windows 10 和 Visual Studio 2019(又名 Visual Studio 14)中使用 set CL=-FI"%VCINSTALLDIR%\include\stdint.h"
    【解决方案2】:

    我已成功在 python 3.6、Windows 10、Visual Studio 2017 上安装 pycrypto 2.6.1。

    1. 在开始菜单中以管理员权限打开“x86_x64 Cross-Tools Command Prompt for VS 2017”。

    2. set CL=-FI"%VCINSTALLDIR%Tools\MSVC\14.11.25503\include\stdint.h"

    3. pip install pycrypto

    【讨论】:

    • 终于解决了!!只要确保检查 MSVC 文件夹的实际版本,我有14.12.25827。谢谢老哥
    • 谢谢@Marko :-) 对我来说,这三个命令有效。 1. C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build>vcvarsx86_amd64.bat 2. 设置 CL=-FI"%VCINSTALLDIR%Tools\MSVC\14.16.27023\include\stdint .h" 3. pip install pycrypto==2.6.1
    • 我正在考虑将 PayPal 按钮捐赠给这个人
    【解决方案3】:

    感谢user1960422 的回答。
    pycrypto 2.6.1(通过 simple-crypt)/Python 3.6/Windows 10 的 PowerShell 步骤:

    $env:VCINSTALLDIR="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC"
    $env:CL="-FI`"$env:VCINSTALLDIR\INCLUDE\stdint.h`""
    

    Successful simple-crypt / pycrypto install

    我还需要按照https://stackoverflow.com/a/24822876/8751739 中的答案来修复winrandom 模块错误。

    【讨论】:

    • 这对 PowerShell 有帮助,但我还需要 Visual Studio can't build due to rc.exe 才能使链接成功。
    • visual studio 2017 构建工具,在我的情况下,VCINSTALLDIR 位于 VC\Tools\MSVC\14.16.27023
    【解决方案4】:

    使用 PyCryptodome 代替 pycrypto。 pycrypto 是 discontinued 并且不再受到积极支持。 PyCryptodome 公开了与 pycrypto (source) 几乎相同的 API。

    【讨论】:

    • 这个问题是关于编译问题和改用什么
    【解决方案5】:

    我已经在 python 3.6 和 windows 10 上成功安装了 pycrypo 2.6.1。

    1. 设置如下环境变量。
    2. 打开 cmd.exe
    3. 激活虚拟环境
    4. 从 github 下载 pycrypto 2.6.1 版本并解压。
    5. 为 pycrypto 设置环境变量 set CL=/FI"%VCINSTALLDIR%\\INCLUDE\\stdint.h" %CL%
    6. 运行设置命令 python setup.py install
    7. 我的结果在这里

    如果这可以帮助某人,我会很高兴。

    【讨论】:

    • 和原来的答案有什么不同?
    • @user1602 您不必在原始答案中执行以下步骤 --- 1. 以管理员权限打开命令提示符 2. 从您的 VC 版本运行 vsvars32.bat
    • 在您的情况下,您手动设置 VCINSTALLDIR,我通过 vsvars32.bat 进行设置。最后,您提出了相同的解决方案。
    【解决方案6】:
    • 卸载当前的 Python 版本

    • 为 amd64 架构安装 Python

    • 遵循其他公认的解决方案:

      • 打开“用于 VS 2017 的 x86_x64 跨工具命令提示符”
      • 为您的 Visual Studio MSVC 安装路径添加新的环境变量
      • set CL=-FI"%VCINSTALLDIR%Tools\MSVC\14.11.25503\include\stdint.h"
      • pip install pycrypto

    【讨论】:

      【解决方案7】:

      对于遇到与我相同情况的人:

      环境

      • Windows 10 企业版 v10.0.18363 内部版本 18363
      • Python 3.8

      步骤

      1. https://visualstudio.microsoft.com/visual-cpp-build-tools/ 下载 Microsoft C++ 构建工具
      2. 运行以上 setup exe 并安装默认组件
        • MSVC v142 - VS 2019 C++ x64/x86 构建工具
        • Windows 10 SDK
        • 适用于 Windows 的 C++ CMake 工具
        • 测试工具核心功能 - 构建工具
        • C++ AddressSanitizer(实验性)
      3. 重启电脑
      4. 开始菜单> x64 Native Tools Command Prompt for VS 2019,会弹出一个cmd窗口
      5. 执行set CL=-FI"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.27.29110\include\stdint.h"
      6. 在cmd窗口运行pip install pycrypto(可能需要管理员权限)

      【讨论】:

        【解决方案8】:

        对我来说,这解决了它:

        使用 Python 2,我有

        sudo apt-get install python-dev  \
             build-essential libssl-dev libffi-dev \
             libxml2-dev libxslt1-dev zlib1g-dev \
             ...
        

        使用 Python 3,我需要

        sudo apt-get install python3 python-dev python3-dev \
             build-essential libssl-dev libffi-dev \
             ...
        

        安装python-dev python3-dev 为我解决了这个问题!

        【讨论】:

        • 这是 Windows 平台问题,不是 Ubuntu。你的回答在这里无关紧要。
        猜你喜欢
        • 2012-11-27
        • 1970-01-01
        • 1970-01-01
        • 2017-08-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多