Be aware that GnuPG is the "real" name of gpg
, which is only the name of the binary. The python API is called python-gnupg.
The problem will most probably be caused by missing access privileges. As you already realized, each system user has its own GnuPG home directory (thus you provided another user's GnuPG-directory), not accessible by others. Make sure your web server user (probably www-data
) has access to /home/myname/.gnupg
, better export the private key and reimport it from within the webserver's user (GnuPG does not like extensive access rights and might send a warning or deny to run at all otherwise).
You can test if that really is the problem by running sudo -u www-data 'gpg --home-dir /home/myname/.gnupg -d filename
(thus, run gpg
under the web server's user).