程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

The method of using python to install PyCrypto module in Windows environment

編輯:Python

1. Background

Recently, when I used python to crawl ts type data, I found that the directly downloaded ts video could not be played normally. I boldly searched Baidu and found that it was caused by video encryption.After going through Baidu and Google, I came into contact with the pycrypto module, which is mainly used to decrypt encrypted videos.
Since the module was not installed smoothly, I stepped on a lot of pits.Because I know the pain, regret and trouble of stepping on the pit, I deliberately wrote an article to record the method of installing this module, so as to prevent people from jumping into the pit.

2. Install the module

2.1 run pip command

pip install pycryptodome

If there is no error when running the above command, then congratulations on your successful installation, you can go directly to the third link.

2.2 Microsoft Visual C++ 14.0 is required.

After running the pip command, it is found that the error message is displayed directly. The error message is as follows:

After some attempts, the solution is as follows:
Download and install visual studio, and install the components of c++ 14.0, as shown below.

2.3 gcc error

If you run it again and it prompts gcc to report an error, congratulations!Won a jackpot!This is due to the configuration file in anaconda.Share here, the solution to this problem.

  • Step a: Find the anaconda directory, find the distutils.cfg file, the default path is: anaconda\Lib\distutils\distutils.cfg
  • Step b: Change compiler=mingw32 to compiler=msvc

3. Use Cases

from Crypto.Cipher import AES# corresponding modulefrom Crypto.Util.Padding import pad#create parser#Note that the key needs to be in binary formcryptor = AES.new(key, AES.MODE_CBC, iv)# becomes a multiple of 16, some scenarios may require#encrypted_data = pad(string, 16)#data is the binary string that needs to be decryptedresult = cryptor.decrypt(data)

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved