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
The error "FileNotFoundError: [Errno 2] No such file or directory" is telling you that there is no file of that name in the working directory. So, try using the exact, or absolute path. In the above code, all of the information needed to locate the file is contained in the path string - absolute path.
The error FileNotFoundError Errno 2 no such file or directory occurs when Python cannot find the specified file in the current directory. Here is an example: main.py. employee1.csv.
The Python "FileNotFoundError: [Errno 2] No such file or directory" occurs when we try to open a file that doesn't exist in the specified location. To solve the error, move the file to the directory where the Python script is located if using a local path, or use an absolute path.
To solve No Such File Or Directory Error in Python, ensure that the file exists in your provided path. To check all the files in the directory, use the os. listdir() method.
Filenotfounderror Errno 2 no such file or directory is a python error always comes when you are not defining proper path for the file or file does not exist in the directory. In this entire tutorial, you will know how to solve Filenotfounderror Errno 2 no such file or directory in an easy way in different scenarios.
The ‘FileNotFoundError’ raises ‘ errorno 2 no such file or directory ‘ when using the os library to read a given file or a directory, and that operation fails. The ‘IOError’ raises ‘ errorno 2 no such file or directory ‘ when trying to access a file that does not exist in the given location using the open () function.
Python FileNotFoundError: [Err... In most cases, any file you reference in a Python program needs to exist. This is, of course, unless you are creating a new file and writing to it. If you reference a file that does not exist, Python will return an error.
You are using a relative path, which means that the program looks for the file in the working directory. The error is telling you that there is no file of that name in the working directory. Try using the exact, or absolute, path.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With