yj
2026-03-31 033d919018b3a3e12755f008c0b9093364942512
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# -*- mode: python ; coding: utf-8 -*-
 
from PyInstaller.utils.hooks import collect_all
import certifi
import os
import sys
import glob
 
# 收集Crypto相关的所有文件
crypto_datas, crypto_binaries, crypto_hiddenimports = collect_all('Crypto')
 
block_cipher = None
 
# 获取Python环境路径
python_path = os.path.dirname(sys.executable)
conda_env_path = os.path.dirname(python_path)  # conda环境根目录
 
# 查找SSL相关的DLL文件
ssl_dlls = []
possible_paths = [
    os.path.join(python_path, 'DLLs'),
    os.path.join(python_path, 'Library', 'bin'),
    os.path.join(conda_env_path, 'Library', 'bin'),
    os.path.join(conda_env_path, 'DLLs'),
    python_path,
]
 
# 需要查找的DLL文件模式
dll_patterns = [
    'libcrypto-*.dll',
    'libssl-*.dll',
    '_ssl*.pyd',
    '_hashlib*.pyd',
    '_socket*.pyd',
    'select*.pyd',
]
 
# 在可能的路径中查找DLL文件
found_dlls = []
for path in possible_paths:
    if os.path.exists(path):
        for pattern in dll_patterns:
            files = glob.glob(os.path.join(path, pattern))
            for file in files:
                if os.path.exists(file):
                    found_dlls.append((file, '.'))
                    print(f"Found: {file}")
 
# 如果没有找到必要的DLL,尝试其他方法
if not found_dlls:
    # 尝试从site-packages中查找
    import site
    for site_path in site.getsitepackages():
        for pattern in dll_patterns:
            files = glob.glob(os.path.join(site_path, '..', 'Library', 'bin', pattern))
            for file in files:
                if os.path.exists(file):
                    found_dlls.append((file, '.'))
                    print(f"Found in site-packages: {file}")
 
a = Analysis(
    ['app.py'],
    pathex=[],
    binaries=crypto_binaries + found_dlls,
    datas=[
        ('config.json', '.'),
        (certifi.where(), 'certifi'),
    ] + crypto_datas,
    hiddenimports=crypto_hiddenimports + [
        'Crypto.Cipher.AES',
        'Crypto.Util._cpuid_c',
        'Crypto.Util._raw_api',
        'flask',
        'jinja2',
        'werkzeug',
        'certifi',
        'urllib3',
        'requests',
        'ssl',
        '_ssl',
        '_socket',
        '_hashlib',
        '_ctypes',
        'select',
    ],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=['jaraco', 'pkg_resources'],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)
 
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
 
exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.zipfiles,
    a.datas,
    [],
    name='app',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    upx_exclude=[],
    runtime_tmpdir=None,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)