当前位置:   article > 正文

pycryptodomex安装过程踩坑解决

pycryptodomex

前言:装TA,要用pycryptodomex,但出现了toolchain\py版本不匹配,网络上太多方法,五花八门,我需要记录整理下思路,所以作此文

Cryptodome是Python语言的加密和解密库,它是PyCrypto和Crypto工具包的继承者。

安装Cryptodome库

有多种方法可以安装Cryptodome库。
最常见的方法是使用pip工具在命令行中运行以下命令:

pip install pycryptodome
  • 1

如果你使用的是Python 3,则需要使用以下命令:

pip3 install pycryptodome
  • 1

请注意,如果已经安装了Crypto工具包或PyCrypto,那么你需要卸载它们:

pip uninstall Crypto
pip uninstall pycrypto
  • 1
  • 2

CommandNotFound

输入pip3 install pycryptodomex ,我想要安装pycryptodomex,但提示我没有 ‘CommandNotFound’

$ pip3 install pycryptodomex 
Traceback (most recent call last):
  File "/usr/lib/command-not-found", line 27, in <module>
    from CommandNotFound.util import crash_guard
ModuleNotFoundError: No module named 'CommandNotFound'
  • 1
  • 2
  • 3
  • 4
  • 5

方法一
参考国外askubuntu上的解决方法:

这个问题发生在我从源代码安装python3.7时。

检查/usr/lib/command-not-found文件,它试图找到模块CommandNotFound,但是python3.7没有提供此模块,而Ubuntu在目录/usr/lib/python3/dist-packages下有该模块。

我们需要做的是将该目录添加到python导入路径中:

1、vi .bashrc (or .profile)
2、添加行

export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.7/site-packages:/usr/lib/python3/dist-packages
  • 1

注意你可能需要将/usr/local/lib/python3.7/site-packages更改为你自己的目录。
3、退出后输入 source .bashrc (or .profile)

方法二
参考python社区
主要问题可能是你安装了新版的python(python3.7)或者别的版本,然后在/usr/bin下将名为python3的软链接指向了新版本的python。因为Python版本不同,Python的模块有些许的不同,而新版本的python没有’CommandNotFound’模块。
解决办法是:
进入报错的文件,如我这里是/usr/lib/cnf-update-db.

vim /usr/lib/cnf-update-db
  • 1

进入该文件,将第一行改为#!/usr/bin/python3.6 即可

注意:这里python3.6是我系统自带的python版本

在这里插入图片描述
方法三
去网站下载安装

  1. 在之前的AES加密中,Python 2或者Python 3.4使用的是pyCrypto模块。然而,最近我尝试安装它时遇到了很多困难,并且发现该库已经停止维护。尽管我使用"pip install pycrypto"命令下载了相应的tar.gz文件,但在自动安装过程中出现了错误,提示缺少Microsoft Visual C++ 2014工具环境。

  2. 继续查阅后,我发现pyCrypto库有一个后续分支叫做pyCryptodome,它是前代的延伸版。如果遇到通过pip无法安装的库,你可以访问以下网站获取对应的下载地址:https://www.pycryptodome.org/

https://www.lfd.uci.edu/~gohlke/pythonlibs/
在这里插入图片描述我这边进去F12没找到
在这里插入图片描述

方法四

参考的是:pip install pycryptodome失败的解决办法

浏览器直接下载:点我下载“pycryptodome-3.9.7-cp38-cp38-win_amd64.whl”

下载完成的whl文件会自动保存至python下的Scripts文件夹下,复制路径直接pip install 路径即可完成安装:
在这里插入图片描述

之后打开python下的site-packages文件夹就会发现多了一个Crypto文件夹(以前是crypto,在导包的时候会出错,需要手动改成大写的C),现在貌似不用了。
在这里插入图片描述

打开Crypto包,会发现里面的一些扩展库:
在这里插入图片描述

这些库正是我们所需要的。


$ python -m pip install --upgrade pip
Exception:
Traceback (most recent call last):
  File "/usr/local/python365/lib/python3.6/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/local/python365/lib/python3.6/site-packages/pip/commands/install.py", line 272, in run
    with self._build_session(options) as session:
  File "/usr/local/python365/lib/python3.6/site-packages/pip/basecommand.py", line 72, in _build_session
    insecure_hosts=options.trusted_hosts,
  File "/usr/local/python365/lib/python3.6/site-packages/pip/download.py", line 329, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/usr/local/python365/lib/python3.6/site-packages/pip/download.py", line 93, in user_agent
    from pip._vendor import distro
  File "/usr/local/python365/lib/python3.6/site-packages/pip/_vendor/distro.py", line 1050, in <module>
    _distro = LinuxDistribution()
  File "/usr/local/python365/lib/python3.6/site-packages/pip/_vendor/distro.py", line 594, in __init__
    if include_lsb else {}
  File "/usr/local/python365/lib/python3.6/site-packages/pip/_vendor/distro.py", line 931, in _get_lsb_release_info
    raise subprocess.CalledProcessError(code, cmd, stdout, stderr)
subprocess.CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1.
Traceback (most recent call last):
  File "/usr/local/python365/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/python365/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/python365/lib/python3.6/site-packages/pip/__main__.py", line 19, in <module>
    sys.exit(pip.main())
  File "/usr/local/python365/lib/python3.6/site-packages/pip/__init__.py", line 248, in main
    return command.main(cmd_args)
  File "/usr/local/python365/lib/python3.6/site-packages/pip/basecommand.py", line 251, in main
    timeout=min(5, options.timeout)) as session:
  File "/usr/local/python365/lib/python3.6/site-packages/pip/basecommand.py", line 72, in _build_session
    insecure_hosts=options.trusted_hosts,
  File "/usr/local/python365/lib/python3.6/site-packages/pip/download.py", line 329, in __init__
    self.headers["User-Agent"] = user_agent()
  File "/usr/local/python365/lib/python3.6/site-packages/pip/download.py", line 93, in user_agent
    from pip._vendor import distro
  File "/usr/local/python365/lib/python3.6/site-packages/pip/_vendor/distro.py", line 1050, in <module>
    _distro = LinuxDistribution()
  File "/usr/local/python365/lib/python3.6/site-packages/pip/_vendor/distro.py", line 594, in __init__
    if include_lsb else {}
  File "/usr/local/python365/lib/python3.6/site-packages/pip/_vendor/distro.py", line 931, in _get_lsb_release_info
    raise subprocess.CalledProcessError(code, cmd, stdout, stderr)
subprocess.CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44

参考网页:
1、DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Pytho
2、python3.6安装pycrypto
3、解决ModuleNotFoundError: No module named ‘CommandNotFound’问题
4、DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020.
5、pip documentation v23.3.dev0(官网)
6、python3.6 实现AES加密的示例(pyCryptodome)
7、python ModuleNotFoundError :‘CommandNotFound’
8、什么是pycryptodomex,它与pycryptodome有何不同?
9、python - 什么是 pycryptodomex,它与 pycryptodome 有何不同?
10、Archived: Unofficial Windows Binaries for Python Extension Packages
11、python3.6 安装第三方库 pyCryptodome 实现AES加密
12、ModuleNotFoundError: No module named ‘CommandNotFound’
13、pycryptodome.org(官网)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/558864
推荐阅读
相关标签
  

闽ICP备14008679号