简体   繁体   English

使用密码术的 python 守护程序的 pyinstaller 抛出异常:'没有名为 '_hmacopenssl' 的模块

[英]pyinstaller of python daemon that uses cryptography throws exception: 'No module named '_hmacopenssl'

Hi Stack Overflow Team,嗨堆栈溢出团队,

I have a daemon written in python, using daemon runner.我有一个使用守护进程运行器用 python 编写的守护进程。 ie IE

from daemon import runner
import random
import time

class App():
    def __init__(self):
        self.stdin_path = '/dev/null'
        self.stdout_path = '/dev/null'
        self.stderr_path = '/dev/null'
        self.pidfile_path = '/var/run/my_daemon.pid'
        self.pidfile_timeout = 5
    def run(self):
        seed = random.seed()
        rtime = random.randrange(21600,42300)
        count = 0
        while True:
            count += 1
            main()
            time.sleep(rtime)

app = App()
daemon_runner = runner.DaemonRunner(app)

In this same daemon, I use: from cryptography.fernet import Fernet to decrypt our DB password when the daemon sees a need to write to our remote database.在同一个守护进程中,我使用: from cryptography.fernet import Fernet当守护进程看到需要写入我们的远程数据库时解密我们的数据库密码。 ie IE

from cryptography.fernet import Fernet

def getTheIngredients(recipe):
    cipher_suite = Fernet(recipe['lock_smith'].encode())
    og_kush = cipher_suite.decrypt(recipe['og_kush_repro'].encode())
    raw_bacon = recipe['bacon'].encode()
    the_son_of_anton = Fernet(og_kush)
    bacon = the_son_of_anton.decrypt(raw_bacon)

    return bacon

I deploy this daemon using pyinstaller --onefile my_daemon.py and build an rpm using: rpmbuild -ba my_custom_daemon.spec我使用pyinstaller --onefile my_daemon.py部署此守护程序并使用以下命令构建 rpm: rpmbuild -ba my_custom_daemon.spec

what the spec file looks like:规范文件的样子:

Name: my_daemon
Version: 1.1.1
Release:    0%{?dist}
Summary: my little daemon

Group: Miscellaneous
License: GPL
#URL:
Source0: my_daemon-1.1.1.tar.gz

BuildArch: x86_64
#BuildRequires: systemd
#Requires:

%description
my little daemon that does stuff :-)

%prep
%setup -q

%build

%install
rm -rf $RPM_BUILD_ROOT
install -d -m 0755 $RPM_BUILD_ROOT/usr/local/bin/
install -m 0755 my_daemon $RPM_BUILD_ROOT/usr/local/bin

mkdir -p %{buildroot}%{_unitdir}/
install -m 0644 %{name}.service %{buildroot}%{_unitdir}/

%post
%systemd_post %{name}.service

%clean
rm -rf $RPM_BUILD_ROOT

%files
%doc
/usr/local/bin/my_daemon
%{_unitdir}/my_daemon.service

%changelog
* Tue Jun 08 2021 M E <me@me.com> - 1.1.1-0
- stuff
- more stuff

when my daemon runs, the below exception gets caught:当我的守护程序运行时,会捕获以下异常:

'No module named '_hmacopenssl'

And I'm very certain that the exception has to do with the cryptography.fernet that I added to do the decryption for me.而且我非常确定异常与我添加的为我进行解密的cryptography.fernet有关。 As my daemon was running perfectly fine until I made those changes.因为我的守护进程运行得非常好,直到我做出这些改变。

So running my daemon outside of the built rpm works fine.因此,在构建的 rpm 之外运行我的守护程序可以正常工作。 But as soon as I package it and try run it via the installed rpm, it throws that exception.但是只要我 package 它并尝试通过安装的 rpm 运行它,它就会抛出该异常。

Any assistance / guidance in this regard is greatly appreciated.非常感谢这方面的任何帮助/指导。

You have to add你必须添加

Requires: python3-fernet

But I guess that during installation you will hit "No such package python3-fernet".但我想在安装过程中你会点击“No such package python3-fernet”。 So you will have to package that one first.所以你必须先到 package 那一个。

But it is on PyPI, so it should be easy using pyp2rpm --srpm fernet但它在 PyPI 上,所以使用pyp2rpm --srpm fernet应该很容易

Side note: you have several other issues in your spec and I recommend you reading https://docs.fedoraproject.org/en-US/packaging-guidelines/Python/旁注:您的规范中还有其他几个问题,我建议您阅读https://docs.fedoraproject.org/en-US/packaging-guidelines/Python/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 pyinstaller 时出现错误 No module named 'cryptography' - get error No module named 'cryptography' when using pyinstaller python + 升级密码学 pkg 后没有名为 cryptography.fernet 的模块 - python + No module named cryptography.fernet after upgrade cryptography pkg pyinstaller 没有名为 pyinstaller 的模块 - pyinstaller No module named pyinstaller Pyinstaller抛出“没有命名为multipart的模块”,“没有命名为映像的模块”,“没有命名为文本的模块”,“没有命名为消息的模块” - Pyinstaller throws “No module named multipart”, “No module named image”,“No module named text”,“No module named message” ImportError:没有名为&#39;cryptography&#39;的模块 - ImportError: No module named 'cryptography' ModuleNotFoundError:没有名为“密码学”的模块 - ModuleNotFoundError: No module named 'cryptography' pyinstaller python脚本后没有模块命名错误 - no module named error after pyinstaller python script Python 2.7.3-ImportError:没有名为PyInstaller的模块 - Python 2.7.3 - ImportError: No module named PyInstaller PyInstaller“ImportError:没有名为Pyinstaller的模块” - PyInstaller “ImportError: No module named Pyinstaller” 电报-python-bot ImportError No module named 'cryptography' Alpine Docker - telegram-python-bot ImportError No module named 'cryptography' Alpine Docker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM