python - 引用原始脚本路径的 Cx_freeze 独立文件
问题描述
伙计们,我真的需要你们的帮助,我要出去度假,但我无法设置我仍然每天使用的脚本在另一台机器上运行。
在我的代码中,我使用 pdf2image 转换器来检查是否正确填充了某些文件。我踩到了这个错误,无法通过,希望你能帮忙。
这是我想要独立的代码的一部分
import PyPDF2
import openpyxl
from datetime import datetime, timedelta
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.common.exceptions import NoSuchElementException as NSEE
from selenium.common.exceptions import TimeoutException as TimeExpt
from selenium.common.exceptions import NoAlertPresentException as NAPE
from selenium.common.exceptions import StaleElementReferenceException as SERE
from selenium.common.exceptions import ElementNotInteractableException as ENIE
import shutil
from tkinter.filedialog import askopenfilename, askdirectory
from PIL import Image
import pytesseract
import sys
from pdf2image import convert_from_path
def verificar_Guias(docs_encontrados, NrID, valorVerif):
for z in range(0,len(docs_encontrados)):
if 'NOTA' not in docs_encontrados[z].upper():
PDF_fileGuia = docs_encontrados[z]
elif 'NOTA' in docs_encontrados[z].upper():
PDFfileNota = docs_encontrados[z]
pages = convert_from_path(PDF_fileGuia, 200, output_folder = path_robo + '\\OCR', poppler_path= path_robo+ '\\poppler-20.12.1\\Library\\bin' ,output_file='nome do arquivo')
pytesseract.pytesseract.tesseract_cmd = path_robo + '\\Tesseract-OCR\\tesseract.exe'
image_counter = 1
for page in pages:
filenameGuia = path_robo+ "\\OCR\\page_"+str(image_counter)+".jpg"
page.save(filenameGuia, 'JPEG')
image_counter = image_counter + 1
outfile = path_robo + '\\OCR\\' + PDF_fileGuia.replace('pdf','txt')
f = open(outfile, "a")
text = str(((pytesseract.image_to_string(Image.open(filenameGuia)))))
if text.find(valorVerif) > 1:
print('Ok')
valorGuia = text[text.find(valorVerif):text.find(valorVerif)+len(valorVerif)]
break
else:
if text.find('FEDTJ')> 0 or text.find('FEDTI')> 0:
valorGuia = text[text.find('Valor Total ')+12:text.find(',',text.find('Valor Total ')+12)+3]
else:
valorGuia = text[text.find('valor: R$ ')+10:text.find(',',text.find('valor: R$ ')+10)+3]
我的 cx_freeze 设置:
from cx_Freeze import setup, Executable
if sys.platform == "win32":
base = "Win32GUI"
executables = [Executable("Bot - Com OCR funcional 2.py", base=base)]
includefiles = [os.path.dirname(pdf2image.__file__),'chromedriver.exe','Leia-me.txt',r'C:\Users\renat\OneDrive\Área de Trabalho\Scripts\Funcionando\ok\Inserir OBP\Tesseract-OCR',r'C:\Users\renat\OneDrive\Área de Trabalho\Scripts\Funcionando\ok\Inserir OBP\poppler-20.11.0']
#excludes = ['pandas','matplotlib','numpy','sqlite3','scipy']
packages = ["os", "time", "PyPDF2", "openpyxl" , "datetime" , "tkinter","selenium", "sys", "pytesseract","PIL","pdf2image"]
options = {
'build_exe': {
'packages':packages,
'include_files':includefiles,
#'excludes':excludes,
},
}
setup(
name = "Inserção de Ocorrências",
options = options,
version = "1.0",
description = 'Robô de inserção de ocorrências',
executables = executables
错误消息(在另一台电脑上运行时)是:
DevTools listening on ws://127.0.0.1:49743/devtools/browser/ee6228c9-e07e-4c22-9087-10bc6c4d9046
C:/Users/Renato/Desktop/Renato - 12-03-2021.xlsx
156572020--8
Traceback (most recent call last):
File "C:\Users\renat\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pdf2image\pdf2image.py", line 441, in pdfinfo_from_path
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2288.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 858, in __init__
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2288.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 1311, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\renat\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\cx_Freeze\initscripts\__startup__.py", line 41, in run
File "C:\Users\renat\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\cx_Freeze\initscripts\Console.py", line 36, in run
File "Bot - Com OCR funcional 2.py", line 237, in <module>
File "Bot - Com OCR funcional 2.py", line 59, in verificar_Guias
File "C:\Users\renat\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pdf2image\pdf2image.py", line 97, in convert_from_path
File "C:\Users\renat\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\pdf2image\pdf2image.py", line 467, in pdfinfo_from_path
pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?
如果有人可以帮助我,我会很受欢迎,因为这是唯一让我远离我已经推迟的假期的事情
解决方案
推荐阅读
- perl - 在 perl 中实例化函数中的哈希效率低吗?
- c++ - 为什么函数“funct”没有被执行?
- node.js - 错误:在安装 CRA 应用程序的纱线时写入 EIO 错误
- node.js - 如何在我的代码(Node.js&Discord.js)中解决这个问题:“node:8036”?
- javascript - 动态添加 colspan 并删除下一个 td
- javascript - 使用 knex 和 mysql 在 where 中使用嵌套选择从 where 中选择
- python - 使用 matplolib 在股票图表上跳过周末
- r - 您如何将 rJava 标准捕获为 R 字符向量?
- html - Bootstrap 4 模态背景在移动设备上没有响应
- response - JHipster yeoman 根据选择的选项重复提示