FileNotFoundError: [Errno 2] No such file or directory: 'tinycss2\\VERSION'

FileNotFoundError: [Errno 2] No such file or directory: 'tinycss2\\VERSION'

完整的错误是:

FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\grossj\AppData\Local\Temp\_MEI143642\tinycss2\VERSION'
[21148] Failed to execute script main

完整的错误日志是:

Traceback (most recent call last):
  File "main.py", line 11, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "c:\users\grossj\desktop\dxf-to-png-converter-master\dxf2png\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 489, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\svglib\svglib.py", line 42, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "c:\users\grossj\desktop\dxf-to-png-converter-master\dxf2png\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 489, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\cssselect2\__init__.py", line 18, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "c:\users\grossj\desktop\dxf-to-png-converter-master\dxf2png\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 489, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\cssselect2\compiler.py", line 3, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "c:\users\grossj\desktop\dxf-to-png-converter-master\dxf2png\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 489, in exec_module
    exec(bytecode, module.__dict__)
  File "site-packages\tinycss2\__init__.py", line 10, in <module>
  File "pathlib.py", line 1206, in read_text
  File "pathlib.py", line 1193, in open
  File "pathlib.py", line 1046, in _opener
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\grossj\AppData\Local\Temp\_MEI143642\tinycss2\VERSION'
[21148] Failed to execute script main

当我使用 pyinstaller -F main.py 构建程序时出现此错误当我 运行 代码 Visual Studio 代码中的代码时,程序运行得非常好。

我尝试用 pip install 安装 tinycss2 但它已经安装了。

我的项目导入是:

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5 import *
from PyQt5.QtPrintSupport import QPrintDialog, QPrinter
from PyQt5 import uic, QtCore, QtWidgets, QtPrintSupport, QtGui
from functools import partial
from dxf2svg.pycore import save_svg_from_dxf, extract_all
from svglib.svglib import svg2rlg
from reportlab.graphics import renderPM
from shutil import copyfile
import sys, os, json, cv2, time, threading,ezdxf, imutils
import numpy as np

您需要为 tinycss2cssselect2 编写挂钩,因为 PyInstaller 没有正确捆绑它们。

因此,首先,在与脚本相同的目录中创建一个名为 hooks 的目录:

- myfile.py
- hooks
  - hook-cssselect2.py
  - hook-tinycss2.py

然后,在 both 钩子文件中 - 它们需要相同 - 复制以下文本:

from PyInstaller.utils.hooks import collect_data_files


def hook(hook_api):
    hook_api.add_datas(collect_data_files(hook_api.__name__))

然后,在构建时,添加选项--additional-hooks-dir=hooks