Вот соответствующий фрагмент кода:
Код: Выделить всё
import os
from docx import Document
from docx2pdf import convert
doct = 'PDF.docx'FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\JUSanche\\AppData\\Local\\Temp\\_MEI2642\\searchdata.txt'
docn = 'Reporte de búsqueda.docx'
data_dir_path = os.path.dirname(os.path.abspath(__file__))
data_relative_path = "searchdata.txt"
data_full_path = os.path.join(data_dir_path, data_relative_path)
ubicaciondocx = os.path.join(data_dir_path, docn)
# ... (rest of the code)
doc.save(ubicaciondocx)
pdf_name = docn.replace('.docx', '.pdf')
convert(ubicaciondocx, pdf_name)
os.startfile(pdf_name)
Точное сообщение об ошибке:
введите здесь описание изображения
Код: Выделить всё
FileNotFoundError:
#Comment:
#Expected result: C:/GENSET-POWER-TABLE/Genset-Power-Table/searchdata.txt
#Result: C:/Users/JUSanche/AppData/Local/Temp/_MEI2642/searchdata.txt
Код: Выделить всё
os.path.dirname(os.path.abspath(__file__))
Код: Выделить всё
os.getcwd()
Код: Выделить всё
os.path.realpath()
Вопросы:
- Почему .exe-файл ищет в другом каталог, чем файл .py?
- Как убедиться, что .exe находит правильный путь к файлу searchdata.txt?
Есть ли способ объединить необходимые текстовые и docx-файлы с расширением .exe?
Подробнее здесь: https://stackoverflow.com/questions/791 ... when-tryin