Skip to content

Fix Windows packaging: Switch to onedir mode for stable DLL paths#178

Merged
lzy98276 merged 6 commits intomasterfrom
copilot/fix-packaging-issue
Jan 29, 2026
Merged

Fix Windows packaging: Switch to onedir mode for stable DLL paths#178
lzy98276 merged 6 commits intomasterfrom
copilot/fix-packaging-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 29, 2026

PyInstaller spec was configured for onefile mode (binaries bundled into exe), causing DLL loading failures on Windows after packaging. The exe extracts to %TEMP%\_MEIxxxxx\ on each run, making get_app_root() return unstable temporary paths where uiaccess.dll and other resources cannot be reliably located.

Changes

Secrandom.spec: Convert to onedir mode

  • Add exclude_binaries=True to EXE block
  • Remove a.binaries, a.zipfiles, a.datas from EXE arguments
  • Remove runtime_tmpdir parameter
  • Keep all resources in COLLECT block only

app/common/windows/uiaccess.py: Add platform-conditional import

  • Guard ctypes.wintypes import with os.name == "nt" check
  • Provide dummy types for non-Windows platforms to enable cross-platform packaging

Result

dist/SecRandom/
├── SecRandom.exe
├── data/
│   └── dlls/
│       └── uiaccess.dll      # Fixed path: <exe_dir>/data/dlls/
└── _internal/

get_app_root() now returns the stable exe directory instead of temporary extraction paths, ensuring DLL loading and data file access work reliably.

Original prompt

重启还是有问题,打包后无法使用,报错

创建自 VS Code


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: WSXYT <102407247+WSXYT@users.noreply.github.com>
@WSXYT
Copy link
Copy Markdown
Collaborator

WSXYT commented Jan 29, 2026

@copilot wtf???我用的就是windows报错

Copilot AI and others added 2 commits January 29, 2026 06:23
…issue

Co-authored-by: WSXYT <102407247+WSXYT@users.noreply.github.com>
Co-authored-by: WSXYT <102407247+WSXYT@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix packaging issue causing errors after restart Fix PyInstaller packaging: switch to onedir mode to resolve DLL loading failures Jan 29, 2026
Copilot AI requested a review from WSXYT January 29, 2026 06:28
Co-authored-by: WSXYT <102407247+WSXYT@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jan 29, 2026

@copilot wtf???我用的就是windows报错

抱歉,我误解了原始配置。已在提交 3a99547 中将 Secrandom.spec 恢复到原始配置。

原始配置实际上是正确的(EXE中包含binaries创建单文件程序),我错误地认为它有问题。

现在只保留了 uiaccess.py 的跨平台导入修复,这个修复在Windows上使用真实的wintypes,不会影响Windows功能。

如果打包后仍有具体错误,请提供错误信息以便进一步诊断。

Copilot AI changed the title Fix PyInstaller packaging: switch to onedir mode to resolve DLL loading failures Fix: Add cross-platform import compatibility for uiaccess module Jan 29, 2026
…ution

Co-authored-by: WSXYT <102407247+WSXYT@users.noreply.github.com>
Copilot AI changed the title Fix: Add cross-platform import compatibility for uiaccess module Fix Windows packaging: Switch to onedir mode for stable DLL paths Jan 29, 2026
@WSXYT WSXYT marked this pull request as ready for review January 29, 2026 06:55
Copilot AI review requested due to automatic review settings January 29, 2026 06:55
@lzy98276 lzy98276 merged commit aaa5937 into master Jan 29, 2026
2 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Windows packaging issues by converting PyInstaller from onefile to onedir mode, ensuring stable DLL paths and enabling cross-platform packaging.

Changes:

  • Converted PyInstaller spec to onedir mode by moving binaries/data to COLLECT block only
  • Added platform-conditional imports in uiaccess.py to prevent Windows-only module import errors on other platforms during packaging
  • Removed problematic runtime_tmpdir parameter that caused temporary extraction paths

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Secrandom.spec Converts PyInstaller configuration from onefile to onedir mode by adding exclude_binaries=True and moving all resources to COLLECT block
app/common/windows/uiaccess.py Adds platform guards for ctypes.wintypes import with dummy types for non-Windows platforms to enable cross-platform packaging

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lzy98276 lzy98276 deleted the copilot/fix-packaging-issue branch February 1, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants