python 安装库pycrypto失败的一系列问题[已解决]

需要安装pycrypto这个库。

/*****************安装pycryptodome***********************/

说来难受,后面发现这个貌似不再维护了,可以安装另外一个库pycryptodome,是这个库的延伸版本,和这个库的作用是一样的,我也是看别人的。
安装pycryptodome

pip install pycryptodome
/*****************安装pycryptodome***********************/

安装pycrypto

需要安装pycrypto的继续:注意3.9以上版本的python可能都无法使用。存在一个错误。

  File "c:\Users\ice\Desktop\112.py", line 7, in <module>
    cipher = AES.new(key, AES.MODE_ECB)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\software\compiler\python\python3.11.5\Lib\site-packages\Crypto\Cipher\AES.py", line 95, in new
    return AESCipher(key, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\software\compiler\python\python3.11.5\Lib\site-packages\Crypto\Cipher\AES.py", line 59, in __init__
    blockalgo.BlockAlgo.__init__(self, _AES, key, *args, **kwargs)
  File "D:\software\compiler\python\python3.11.5\Lib\site-packages\Crypto\Cipher\blockalgo.py", line 141, in __init__
    self._cipher = factory.new(key, *args, **kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats

目前知道是要加宏定义

Note For all # variants of formats (s#, y#, etc.), the macro PY_SSIZE_T_CLEAN must be defined before including Python.h. On Python 3.9 and older, the type of the length argument is Py_ssize_t if the PY_SSIZE_T_CLEAN macro is defined, or int otherwise.

但是还没有测试,不知道要怎么加。

python3.8版本测试是可以使用的。python3.8版本以下都可以使用。
应该是不兼容。python3.9以上版本,需要有定义
继续安装 pycrypto

pip install pycrypto

但是直接安装就会出现错误如下:

Building wheels for collected packages: pycrypto
  Building wheel for pycrypto (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for pycrypto (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [2 lines of output]
      warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
      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 pycrypto
Failed to build pycrypto
ERROR: Could not build wheels for pycrypto, which is required to install pyproject.toml-based projects

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/

这说需要一个C++ 14.0以上的版本
https://visualstudio.microsoft.com/visual-cpp-build-tools/
去这个网址下载一个安装工具

下载工具

下载后直接运行安装

安装
在下载过程中还可以确认一个东西,但是实际上只要下载了python版本都自己带有,不管是老版本还是新版本,3.8,3.11亲测都有,这个东西就是setuptools。这个的版本应该和python安装的时间有关,安装早的版本可能会老一点。
安装这个c++编译器 Microsoft Visual C++ ,需要有配对的setuptools版本。
安装最新的Microsoft Visual C++,需要配备最新的setuptools。(实践证明较新的也可以,估测60版本以上都可以)

Microsoft Visual C++ 14.2 standalone: Build Tools for Visual Studio 2019 (x86, x64, ARM, ARM64)
This is a standalone version of Visual C++ 14.2 compiler, you don't need to install Visual Studio 2019.

In Build tools, install C++ build tools and ensure the latest versions of MSVCv142 - VS 2019 C++ x64/x86 build tools and Windows 10 SDK are checked.
The setuptools Python package version must be at least 34.4.0.

安装Visual C++ 14.2 compiler版本的需要setuptools至少34.4.0。
详细版本对应可以参考Visual C++ 14.2 compiler对应版本

查看setuptools版本的方法。

>>> import setuptools
>>> print(setuptools._version__)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'setuptools' has no attribute '_version__'. Did you mean: '__version__'?
>>> print(setuptools.__version__)
65.5.0

我查了3.8和3.11的python,版本差别不大的,都是高版本(11:68)。我的是65版本,可以直接安装最新的Visual C++ 14.3。(setuptools的版本应该和python版本关系不大,和python的安装时间有关,大家可以查看自己的版本,在65以上必然就可以安装最新的)

安装好后会出现如下界面:

C++
选中使用C++的桌面开发这个即可,然后右边有默认选项,会默认选了五个,后两个可以不用选,不会有影响,但是选上也没占多少内存。建议默认选项即可。
最好是默认,默认可以成果,其他的可能存在错误(选低版本的SDK和编译器会报错)
另外这里要注意选的是windows 11 SDK,这个无论你是window10的系统还是window11的系统都可以安装,亲测有效,win7其他的就不清楚了。
同时还可以修改安装位置,安装这个编译器包括这个window11SDK,总共大小有接近6G,可以换到其他盘进行安装,同时也可以取消勾选保留下载缓存。
选择安装
下载安装需要一定时间,不需要连到外网也可以下载。

ok
安装好后继续输入:

pip install pycrypto

发现会有另外一个错误。

error

 C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt\inttypes.h(31): error C2061: 语法错误: 标识符“intmax_t”

提示这个文件存在语法错误。标识符错误,这个变量类型错误。

参考这篇文章解决的。
https://blog.csdn.net/miffy2017may/article/details/107546033
方法如下:
1、找到你刚刚下载的编译器保存的文件位置。

C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.39.33519\include

默认是这个路径,可能版本区别,路径会有些许区别,但也可以找到。

2、找到这个路径下的一个文件stdint.h,复制该文件
stdint.h
3、找到另外一个文件夹C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt
这个文件夹,大家都有的,将上一步复制的stdint.h复制到这个文件夹下。

4、编辑该文件夹下的inttypes.h文件,记事本打开即可

inttypers.h
5、修改文件中的#include <stdint.h>,为 #include “stdint.h”,就是把尖括号改为双引号。涉及c头文件读取方面的问题。

xiu
完成上面步骤,再次运行命令 pip install pycrypto

succeed
这样就成功安装pycrypto

貌似没用了,都2024年了,用pycryptodome吧。
安装pycryptodome

pip install pycryptodome

这是注定一个悲剧的晚上,以此篇注定无人问津的文章哀悼。

版权声明:本文为博主作者:NS_ice原创文章,版权归属原作者,如果侵权,请联系我们删除!

原文链接:https://blog.csdn.net/NS_ice/article/details/136542917

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
青葱年少的头像青葱年少普通用户
上一篇 2024年4月22日
下一篇 2024年4月22日

相关推荐