Issue
I have a Dockerfile with PyQT installed like below
FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive
RUN adduser --quiet --disabled-password qtuser && usermod -a -G audio qtuser
RUN apt-get update -y \
&& apt-get install alsa -y \
&& apt-get install -y python3-pyqt5 \
&& apt-get install python3-pip -y && \
pip3 install pyqtwebengine
WORKDIR /htmltopdf
I built my image like this docker build -t html-to-pdf .
Then I ran my image like this docker run --rm -v "$(pwd)":/htmltopdf -u qtuser -it html-to-pdf python3 htmlToPdfnew.py --url https://www.w3schools.com/howto/howto_css_register_form.asp
But I'm getting below error
Traceback (most recent call last):
File "htmlToPdfnew.py", line 2, in <module>
from PyQt5 import QtWidgets, QtWebEngineWidgets
ImportError: libsmime3.so: cannot open shared object file: No such file or directory
I do NOT get that error in my PC.
below is my python code
import sys
from PyQt5 import QtWidgets, QtWebEngineWidgets
from PyQt5.QtCore import QUrl, QTimer
from PyQt5.QtGui import QPageLayout, QPageSize
from PyQt5.QtWidgets import QApplication
import argparse
def main():
url = ''
parser = argparse.ArgumentParser(description="Just an example", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--url", help="Type url")
args = parser.parse_args()
config = vars(args)
url = config['url']
app = QtWidgets.QApplication(sys.argv)
loader = QtWebEngineWidgets.QWebEngineView()
loader.setZoomFactor(1)
layout = QPageLayout()
layout.setPageSize(QPageSize(QPageSize.A4Extra))
layout.setOrientation(QPageLayout.Portrait)
loader.load(QUrl(url))
loader.page().pdfPrintingFinished.connect(lambda *args: QApplication.exit())
def emit_pdf(finished):
QTimer.singleShot(2000, lambda: loader.page().printToPdf("test.pdf", pageLayout=layout))
loader.loadFinished.connect(emit_pdf)
sys.exit(app.exec_())
if __name__ == '__main__':
main()
so how do I resolve below error ?
Traceback (most recent call last):
File "htmlToPdfnew.py", line 2, in <module>
from PyQt5 import QtWidgets, QtWebEngineWidgets
ImportError: libsmime3.so: cannot open shared object file: No such file or directory
Solution
You have to install libnss3 in the Docker image.
Adding apt-get install libnss3
to your installation commands in the Dockerfile
should do the trick.
Answered By - Klaus D.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.