需要安裝pycrypto這個庫。
/*****************安裝pycryptodome***********************/
說來難受,后面發(fā)現(xiàn)這個貌似不再維護了,可以安裝另外一個庫pycryptodome,是這個庫的延伸版本,和這個庫的作用是一樣的,我也是看別人的。
安裝pycryptodome
pip install pycryptodome
/*****************安裝pycryptodome***********************/
安裝pycrypto
需要安裝pycrypto的繼續(xù):注意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以上版本,需要有定義
繼續(xù)安裝 pycrypto
pip install pycrypto
但是直接安裝就會出現(xiàn)錯誤如下:
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/
去這個網(wǎng)址下載一個安裝工具
下載后直接運行安裝
在下載過程中還可以確認一個東西,但是實際上只要下載了python版本都自己帶有,不管是老版本還是新版本,3.8,3.11親測都有,這個東西就是setuptools。這個的版本應該和python安裝的時間有關(guān),安裝早的版本可能會老一點。
安裝這個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版本關(guān)系不大,和python的安裝時間有關(guān),大家可以查看自己的版本,在65以上必然就可以安裝最新的)
安裝好后會出現(xiàn)如下界面:
選中使用C++的桌面開發(fā)這個即可,然后右邊有默認選項,會默認選了五個,后兩個可以不用選,不會有影響,但是選上也沒占多少內(nèi)存。建議默認選項即可。
最好是默認,默認可以成果,其他的可能存在錯誤(選低版本的SDK和編譯器會報錯)
另外這里要注意選的是windows 11 SDK,這個無論你是window10的系統(tǒng)還是window11的系統(tǒng)都可以安裝,親測有效,win7其他的就不清楚了。
同時還可以修改安裝位置,安裝這個編譯器包括這個window11SDK,總共大小有接近6G,可以換到其他盤進行安裝,同時也可以取消勾選保留下載緩存。
下載安裝需要一定時間,不需要連到外網(wǎng)也可以下載。
安裝好后繼續(xù)輸入:
pip install pycrypto
發(fā)現(xiàn)會有另外一個錯誤。
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
默認是這個路徑,可能版本區(qū)別,路徑會有些許區(qū)別,但也可以找到。
2、找到這個路徑下的一個文件stdint.h,復制該文件
3、找到另外一個文件夾C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt
這個文件夾,大家都有的,將上一步復制的stdint.h復制到這個文件夾下。
4、編輯該文件夾下的inttypes.h文件,記事本打開即可
5、修改文件中的#include <stdint.h>,為 #include “stdint.h”,就是把尖括號改為雙引號。涉及c頭文件讀取方面的問題。
完成上面步驟,再次運行命令 pip install pycrypto。
這樣就成功安裝pycrypto。
貌似沒用了,都2024年了,用pycryptodome吧。
安裝pycryptodome。文章來源:http://www.zghlxwxcb.cn/news/detail-845242.html
pip install pycryptodome
這是注定一個悲劇的晚上,以此篇注定無人問津的文章哀悼。文章來源地址http://www.zghlxwxcb.cn/news/detail-845242.html
到了這里,關(guān)于python 安裝庫pycrypto失敗的一系列問題[已解決]的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!