我正在尝试使用cx_Freeze创建可执行文件,它会创建exe,但是每当我尝试启动它时,它就会因某些错误而崩溃(请参阅下文)。
setup.py
:
from cx_Freeze import setup, Executable
import sys
import glob
import os
import zlib
import shutil
base = None
# PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = "C:\\ProgramData\\Anaconda3\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\ProgramData\\Anaconda3\\tcl\\tk8.6"
os.environ['TESSERACT_LIBRARY'] = "E:\\Tesseract-OCR"
if sys.platform == 'win32':
base = "Win32GUI"
if sys.platform == 'win64':
base = "Win64GUI"
include = [ 'jinja2', 'jinja2.ext',] #Include packages
includefiles = ['gui/']
options = {'build_exe':{'includes':include,'include_files': includefiles}}
flaskapp = Executable(script="scan_config.py",
targetName="D2D.exe",
)
setup(
name="D2D",
version="1.0",
author="abc",
description="D2d",
options={
'build_exe': {
'include_files': includefiles,
'includes': include,
'build_exe': "build"
}
},
executables=[flaskapp]
)
错误:
回溯(最近通话最近): 文件“ scan_config.py”,第5行,在 来自Jinja2导入转义的文件“ C:\ Users \ abc \ AppData \ Roaming \ Python \ Python37 \ site-packages \ flask__init __。py”,第14行 _patch_async()中的文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ jinja2__init __。py”,第82行 来自jinja2.async的_patch_async中的文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ jinja2__init __。py”,行78,导入import patch_all 导入异步中的文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ jinja2 \ asyncsupport.py”,第13行 文件“ C:\ ProgramData \ Anaconda3 \ lib \ asyncio__init __。py”,从.base_events导入* 从中输入文件“ C:\ ProgramData \ Anaconda3 \ lib \ asyncio \ base_events.py”,进入。导入常量 ImportError:无法从“ asyncio”(E:\ engine \ build \ lib \ asyncio__init __。pyc)导入名称“ constants”
P.S。我也尝试了PyInstaller,但是我不知道如何包含pytesseract。
答案 0 :(得分:1)
我将python版本降级为3.6。那解决了大多数错误。对于jinja2,我做了` try {
String url = "https://jsonplaceholder.typicode.com/posts/1";
URL obj = new URL(url);
System.out.println(obj);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// optional default is GET
con.setRequestMethod("GET");
// add request header
con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:19.0) Gecko/20100101 Firefox/19.0");
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
String final_response = response.toString();
System.out.println(final_response);
} catch (Exception e) {
// TODO: handle exception
System.out.println(e);
}`
,还包括了pip install https://github.com/pallets/jinja/zipball/master
和mkl
文件。在多处理文件夹中,我将libiomp5md
更改为Pool.pyc