Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GnuPG home directory

The following is the code that I have been trying.

import os
import gnupg
import pdb
pdb.set_trace()
gpg = gnupg.GPG(gnupghome='new')
input_data = gpg.gen_key_input(
    key_type="RSA",key_length=1024,
    passphrase='mounika')
key = gpg.gen_key(input_data)
with open(local.txt,'rb')as f:
    status=gpg.encrypt_file(f)

And the following is the error message being generated.

C:\Python27\python.exe C:/SAAS/encrypt.py
Traceback (most recent call last):
  File "C:/SAAS/encrypt.py", line 4, in <module>
    gpg = gnupg.GPG(gnupghome='new')
  File "C:\Python27\lib\site-packages\gnupg.py", line 755, in __init__
    raise OSError(msg)
OSError: Unable to run gpg - it may not be available.

Process finished with exit code 1

I am fairly new to GnuPG and after doing a bit of research I tried replacing gnupghome with homedir. But this is raising another error that homedir is an unexpected keyword.Can soneone pls help me with this issue. Any help would be appreciated.

like image 477
mounika Avatar asked Feb 27 '26 13:02

mounika


1 Answers

You need to install the gpg program and make sure it is in your PATH. Or provide the full path to the gpg binary in your constructor, like

gpg = gnupg.GPG(gnupghome='new', gpgbinary='C:\\path\\to\\GnuPG\\pub\\gpg.exe')

Check also the Deployment Requirements for the python-gnupg package for more info.

like image 151
Grisha Levit Avatar answered Mar 02 '26 13:03

Grisha Levit