zoukankan      html  css  js  c++  java
  • Windows安装pycrypto失败记录

    Windows 10家庭中文版,Python 3.6.4,

    180824测试前端加密文本在后台揭秘,查询后发现,可以使用pycrypto模块实现,那么,安装它(pip),结果安装失败了。

    本文暂时记录下失败的日志,后面找到解决问题了再完善博文。

    pycrypto相关网址:

    PyPI:https://pypi.org/project/pycrypto/

    官网:https://www.dlitz.net/software/pycrypto/

    官文:https://www.dlitz.net/software/pycrypto/api/current/

    使用pip list,没有找到pycrypto,那么,安装它。

    >pip3 install pycrypto

    下面是安装过程日志中的部分错误信息:

    ...

    Running setup.py bdist_wheel for pycrypto ... error
    Complete output from command c:python36python3.exe -u -c "import setuptools, tokenize;__file__='C:\Users\log\AppData\Local\Temp\pip-install-0e9wj35t\pycrypto\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace(' ', ' ');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d C:UserslogAppDataLocalTemppip-wheel-i1adunc1 --python-tag cp36:
    ...
    warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
    ...
    C:Program Files (x86)Microsoft Visual Studio 14.0VCBINx86_amd64cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Isrc/ -Isrc/inc-msvc/ -Ic:python36include -Ic:python36include "-IC:Program Files (x86)Microsoft Visual Studio 14.0VCINCLUDE" "-IC:Program Files (x86)Windows Kits10include10.0.10240.0ucrt" "-IC:Program Files (x86)Windows Kits8.1includeshared" "-IC:Program Files (x86)Windows Kits8.1includeum" "-IC:Program Files (x86)Windows Kits8.1includewinrt" /Tcsrc/winrand.c /Fobuild emp.win-amd64-3.6Releasesrc/winrand.obj
    winrand.c
    C:Program Files (x86)Windows Kits10include10.0.10240.0ucrtinttypes.h(26): error C2061: syntax error: identifier 'intmax_t'
    C:Program Files (x86)Windows Kits10include10.0.10240.0ucrtinttypes.h(27): error C2061: syntax error: identifier 'rem'
    C:Program Files (x86)Windows Kits10include10.0.10240.0ucrtinttypes.h(27): error C2059: syntax error: ';'
    C:Program Files (x86)Windows Kits10include10.0.10240.0ucrtinttypes.h(28): error C2059: syntax error: '}'
    C:Program Files (x86)Windows Kits10include10.0.10240.0ucrtinttypes.h(30): error C2061: syntax error: identifier 'imaxdiv_t'
    C:Program Files (x86)Windows Kits10include10.0.10240.0ucrtinttypes.h(30): error C2059: syntax error: ';'
    ...
    C:Program Files (x86)Windows Kits10include10.0.10240.0ucrtinttypes.h(95): error C2143: syntax error: missing '{' before '__cdecl'
    error: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe' failed with exit status 2
    ...
    ----------------------------------------
    Failed building wheel for pycrypto
    Running setup.py clean for pycrypto
    Failed to build pycrypto
    Installing collected packages: pycrypto
    Running setup.py install for pycrypto ... error
    Complete output from command c:python36python3.exe -u -c "import setuptools, tokenize;__file__='C:\Users\log\AppData\Local\Temp\pip-install-0e9wj35t\pycrypto\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace(' ', ' ');f.close();exec(compile(code, __file__, 'exec'))" install --record C:UserslogAppDataLocalTemppip-record-ux9dvusoinstall-record.txt --single-version-externally-managed --compile:
    running install
    ...
    buildlib.win-amd64-3.6CryptoSignature
    Skipping optional fixer: buffer
    Skipping optional fixer: idioms
    Skipping optional fixer: set_literal
    Skipping optional fixer: ws_comma
    running build_ext
    warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
    building 'Crypto.Random.OSRNG.winrandom' extension
    ...
    C:Program Files (x86)Microsoft Visual Studio 14.0VCBINx86_amd64cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Isrc/ -Isrc/inc-msvc/ -Ic:python36include -Ic:python36include "-IC:Program Files (x86)Microsoft Visual Studio 14.0VCINCLUDE" "-IC:Program Files (x86)Windows Kits10include10.0.10240.0ucrt" "-IC:Program Files (x86)Windows Kits8.1includeshared" "-IC:Program Files (x86)Windows Kits8.1includeum" "-IC:Program Files (x86)Windows Kits8.1includewinrt" /Tcsrc/winrand.c /Fobuild emp.win-amd64-3.6Releasesrc/winrand.obj
    winrand.c
    C:Program Files (x86)Windows Kits10include10.0.10240.0ucrtinttypes.h(26): error C2061: syntax error: identifier 'intmax_t'
    C:Program Files (x86)Windows Kits10include10.0.10240.0ucrtinttypes.h(27): error C2061: syntax error: identifier 'rem'
    C:Program Files (x86)Windows Kits10include10.0.10240.0ucrtinttypes.h(27): error C2059: syntax error: ';'
    C:Program Files (x86)Windows Kits10include10.0.10240.0ucrtinttypes.h(28): error C2059: syntax error: '}'
    ...
    ----------------------------------------
    Command "c:python36python3.exe -u -c "import setuptools, tokenize;__file__='C:\Users\log\AppData\Local\Temp\pip-install-0e9wj35t\pycrypto\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace(' ', ' ');f.close();exec(compile(code, __file__, 'exec'))" install --record C:UserslogAppDataLocalTemppip-record-ux9dvusoinstall-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:UserslogAppDataLocalTemppip-install-0e9wj35tpycrypto
    You are using pip version 10.0.1, however version 18.0 is available.
    You should consider upgrading via the 'python -m pip install --upgrade pip' command.

    ----END----

    从上面的错误日志来看,需要用到一个cl.exe命令,这个命令的路径存在于Microsoft Visual Studio 14.0或Windows Kits中,但是,孤的电脑上是没有的。

    解决的方法当然是安装Microsoft Visual Studio,参考链接的解决方法也是说要安装一个,不过更详细一些。

    另外,错误日志还提示GMP or MPIR library缺失,是否安装好Microsoft Visual Studio就有了呢?然后,之后就可以安装pycrypto了。

    接下来,分为两步解决这个问题:

    1.安装Microsoft Visual Studio;

    2.安装pycrypto(此步骤的日志可以检查GMP or MPIR library是否已经有了,若是没有,且pycrypto安装失败,那么再找办法);

    0825-0900新发现:

    孤的电脑已经有错误日志中提到的Microsoft Visual Studio 14.0或Windows Kits目录及相关文件了,可是看来,上面说的解决方法是不对的,还需要继续dig才是

    操作系统模块安装了Visual Studio 2015的部分功能吗?下图的这些是怎么来的呢?

    既然如此,那么,又要怎么解决呢?再看看参考链接吧!

    去Visual Studio官网看了一遍,好多软件,不愧是Microsoft!对于一位非Windows系程序员,要选对软件有些困难啊!

    还要找找,到底Windows 10上能否安装pycrypto!

    哎呀,都要耗费精时啊!

    检查Python标准库,居然没有找到加密、安全相关的模块,搜索security、crypto都没有找到想要的——使用各种加密算法,看来,必须要用第三方库了,比如pycrypto。

    参考链接:

    windows 下的python 安装pycrypto by 园友 anne的夏天

    python 加密解密 by 园友 jihite

    0825-0930更新:哇哦,Ubuntu(18.04)上安装pycrypto好方便啊!嗖的一下就安装好勒!

    安装好了,可是,import pycrypto失败!

    >>> import pycrypto
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ModuleNotFoundError: No module named 'pycrypto'

    疑问:怎么找到一个模块的用法呢?官网吗?通过模块本身可以知道吗?

    参考下面的链接(官文)可以初步知道pycrypto模块的用法:

    Python Cryptography Toolkit

  • 相关阅读:
    37. Sudoku Solver(js)
    36. Valid Sudoku(js)
    35. Search Insert Position(js)
    34. Find First and Last Position of Element in Sorted Array(js)
    33. Search in Rotated Sorted Array(js)
    32. Longest Valid Parentheses(js)
    函数的柯里化
    俞敏洪:我和马云就差了8个字
    vue路由传值params和query的区别
    简述vuex的数据传递流程
  • 原文地址:https://www.cnblogs.com/luo630/p/9532924.html
Copyright © 2011-2022 走看看