【问题标题】:Couldn't mmap icu data file in PyQt5无法在 PyQt5 中映射 icu 数据文件
【发布时间】:2021-10-04 09:34:06
【问题描述】:

我在 pyqt5 中使用了 QWebEngineView。尝试使用 HTML 文件在 QWebEnginView 中导出 PDF。当我在 VS Code 中运行文件时,pdf 导出并且工作正常,但是当我在 cmd 中使用此命令将此 python 文件转换为 exe 时

pyinstaller --onefile mycode.py

运行 mycode.exe 我得到这个错误:Couldn't mmap icu data file

这是我在 pyqt5 中的全部代码:

import sys
from PyQt5.QtWidgets import (QHBoxLayout, QPushButton, QWidget, 
QApplication, QVBoxLayout, QMessageBox)
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView


class Example(QWidget):

  def __init__(self):
    super().__init__()

    self.initUI()

  def initUI(self):

    vbox = QVBoxLayout(self)
    hbox = QHBoxLayout()

    self.webEngineView = QWebEngineView()
    self.loadPage()

    expBtn = QPushButton('Export', self)
    expBtn.clicked.connect(self.onClicked)

    hbox.addWidget(expBtn)

    vbox.addWidget(self.webEngineView)
    vbox.addLayout(hbox)
    self.setLayout(vbox)

    self.setGeometry(300, 300, 350, 250)
    self.setWindowTitle('QWebEngineView')
    self.show()

  def onClicked(self):

    self.webEngineView.page().printToPdf('myfile.pdf')
    QMessageBox.information(self, 'info', 'page exported')

  def loadPage(self):

    with open('html.html', encoding="utf8") as f:

        html = f.read()
        self.webEngineView.setHtml(html)

def main():

   app = QApplication(sys.argv)
   ex = Example()
   sys.exit(app.exec_())


if __name__ == '__main__':
   main()

这是我的 HTML:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
  
    <style>
        th, td {
          border-bottom:1px solid black;
          border-right:1px solid black;
          text-align : center;
          padding : 3px;
        }
        * {
        direction: rtl;
        }     
        
        .img{
            border-bottom:1px solid black;
          border-right:1px solid black;
          text-align : center;
          
        }
        .center {
            
            margin-left: auto;
            margin-right: auto;
            width:95%;
            border:1px solid black;
            
            }
        </style>
        
    </head>
<body style="font-family: Arial">
    
      <div style="border: 4px double black;">
        <h3 style="text-align:center; font-size: 30px;">فاکتور خرید</h3>
        <h3 style="text-align:center ;font-size: 30px;">شرکت برنا نوآوران پویا</h3>
        <img src="icon.jpg" alt="Paris" style="width: 5%;">
    </div>
    <div style="border-bottom: 1px dashed black; border-left: 4px double black; border-right: 4px double black;border-top: 1px double black;">

        <p style="text-align:right; font-size: 20px; padding-right: 30px;"> تاریخ : </p>
        <p style="text-align:right; font-size: 20px; padding-right: 30px;">زمان :</p>
    </div>
    <div style="border-bottom: 4px double black; border-left: 4px double black; border-right: 4px double black;border-top: 1px dashed black;">
        <br></br>
        
        <table class = "center">
            <tr >
              <th>شماره بارنامه</th>
              <th>تاریخ ورود محموله</th>
              <th>نرخ دلار</th>
              <th>نرخ پوند</th>
              <th>نرخ یورو</th>
              <th>وزن کل</th>
              <th>هزینه گمرک</th>
              <th>هزینه حمل</th>
              <th>هزینه خرید</th>
              <th>هزینه کارمزد</th>
              <th>مجموع هزینه کل</th>
              <th>تعداد کل کالا</th>
              
            </tr>
            <tr>
              <td>3333</td>
              <td>345</td>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td>
              
              
            </tr>
           
          </table>
          <br></br>
        <br></br>
        
          <table class = "center">
            <tr >
              <th>اسم کالا</th>
              <th>تعداد تکی</th>
              <th>قمیت خرید نهایی</th>
              <th>وزن نهایی به گرم</th>
              <th>قیمت کل</th>
              
            </tr>
            <tr>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td>
              <td>30000000</td> 
            </tr>

            <tr>
                <td>30000000</td>
                <td>30000000</td>
                <td>30000000</td>
                <td>30000000</td>
                <td>30000000</td> 
              </tr>

              <tr>
                <td>30000000</td>
                <td>30000000</td>
                <td>30000000</td>
                <td>30000000</td>
                <td>30000000</td> 
              </tr>
              <tr>
                <td>30000000</td>
                <td>30000000</td>
                <td>30000000</td>
                <td>30000000</td>
                <td>30000000</td> 
              </tr>
           
          </table>
          
          <br></br>


        <p style="border-bottom: 1px solid black;border-right: 1px solid black; border-radius: 2px; text-align:right; font-size: 20px; margin-right:30px; width: 50%; height: 40px;">
          <span style="display: inline-block; margin-right: 5px; margin-bottom: 7px; margin-top: 7px;">مجموع قیمت کل :</span>
        <span style="display: inline-block; margin-right: 3px; margin-bottom: 7px; margin-top: 7px;">34343</span>
        </p>
        
          <p style="border-bottom: 1px dashed"></p>
          <br></br>
          <table class = "center">
            <tr >
              <th>فاکتور خرید</th>
              <th>بارنامه</th>
              
              
              
            </tr>
            
              <td class = "img">
                <img src="run.jpg" style="width: 90%;">
              </td>
              <td class = "img">
                <img src="run.jpg" style="width: 90%;">
              </td>
            </tr>

          </table>

          <br></br>
        <br></br>
        
          <table class = "center">
            <tr >
              <th>رسید خرید ۱</th>
              <th>رسید خرید ۲</th>             
              
            </tr>
            
              <td class = "img">
                <img src="run.jpg" style="width: 90%;">
              </td>
              <td class = "img">
                <img src="run.jpg" style="width: 90%;">
              </td>
            </tr>

          </table>

          <br></br>
        <br></br>
        <p style="text-align:right; font-size: 20px; padding-right: 30px;">سرمایه گذاران :</p>
        <br></br>
        <br></br>
        <br></br>
        <p style="text-align:right; font-size: 20px; padding-right: 30px;"></p>

        <p style="text-align:right; font-size: 20px; padding-right: 30px;">توضیحات تکمیلی :</p>
        <br></br>
        <br></br>
        <br></br>
        <p style="text-align:right; font-size: 20px; padding-right: 30px;"></p>

        <p style="text-align:right; font-size: 20px; padding-right: 30px;">نام کاربر :</p>
        <br></br>
        <br></br>
        <br></br>
        <p style="text-align:right; font-size: 20px; padding-right: 30px;"></p>

        


    </div>
</body>

</html>

有谁知道当我将python文件转换为exe时如何解决这个错误?

【问题讨论】:

    标签: python qwebengineview


    【解决方案1】:

    我在一个中文网站上找到了解决方案。 我不得不将一些文件放在 myapp.exe 中。 链接在这里: 访问https://cxyzjd.com/article/meimeieee/115024971

    【讨论】:

    • 仅链接答案是无用的。你能详细说明一下吗?
    猜你喜欢
    • 2015-01-21
    • 2023-04-01
    • 1970-01-01
    • 2022-12-07
    • 2021-10-15
    • 2013-09-23
    • 1970-01-01
    • 2023-03-04
    相关资源
    最近更新 更多