python-3.x RuntimeError:GnuPG未安装

piah890a  于 2023-06-25  发布在  Python
关注(0)|答案(2)|浏览(194)

要求:运行文件的python解密
我已经在MacOS的虚拟环境中安装了gnupg,import gnupg也工作正常,但第二行抛出了如下错误
>>> gpg = gnupg.GPG() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/krajashekaran/.local/share/virtualenvs/mypython-sPLN-T2A/lib/python3.8/site-packages/gnupg/gnupg.py", line 117, in __init__ super(GPG, self).__init__( File "/Users/krajashekaran/.local/share/virtualenvs/mypython-sPLN-T2A/lib/python3.8/site-packages/gnupg/_meta.py", line 182, in __init__ self.binary = _util._find_binary(binary) File "/Users/krajashekaran/.local/share/virtualenvs/mypython-sPLN-T2A/lib/python3.8/site-packages/gnupg/_util.py", line 429, in _find_binary raise RuntimeError("GnuPG is not installed!") RuntimeError: GnuPG is not installed!
代码

import gnupg
gpg = gnupg.GPG()

解决方案:
我终于解决了
1.安装brew install GnuPG

  1. import gnupg gpg = gnupg. GPG('/usr/local/bin/gpg')
r8xiu3jd

r8xiu3jd1#

我安装了一个新的Python版本(3.10.0)和python-gnupg,它开始工作了:

pip3 install python-gnupg
gojuced7

gojuced72#

安装gnupg包

pip install python-gnupg

然后在对象初始化期间显式指定gpg二进制文件的路径。

gpg_binary = '/usr/local/bin/gpg'
gpg = gnupg.GPG(binary=gpg_binary)

相关问题