5

The full error is:

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

The full error log is:

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

I get this error when I build the program with pyinstaller -F main.py The program works perfectly fine when I run the code in Visual Studio Code.

I tried installing tinycss2 with pip install But it was already installed.

My project imports are:

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
JareBear
  • 467
  • 9
  • 27

1 Answers1

5

You need to write hooks for tinycss2 and cssselect2 because PyInstaller isn't bundling them properly.

So first, create a directory called hooks in the same directory as your script:

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

Then, inside both of the hook files - they need to be identical - copy the following text:

from PyInstaller.utils.hooks import collect_data_files


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

Then, when building, add the option --additional-hooks-dir=hooks.

JareBear
  • 467
  • 9
  • 27
Legorooj
  • 2,646
  • 2
  • 15
  • 35
  • 1
    Where exactly do I find these `hook-tinycss2.py` and `hook-cssselect2.py` files, or even `tinycss2.py` and `cssselect2.py`? I can't seem to find them anywhere in my python `lib/sitepackages` directory or my virtual enviroment. – JareBear Apr 30 '20 at 15:50
  • @JareBear you have to make them... Maybe you didn't understand. I've edited with more info – Legorooj Apr 30 '20 at 23:58
  • 1
    Oh thats what you mean! Sorry my bad, I had thought you meant to add the code to my main script, and not inside the 2 new ones that need to be made! I will try that, and get back to you. Thank you so much – JareBear May 01 '20 at 01:46