python - Pyinstaller - 在 dist 中包含空文件夹

标签 python pyinstaller

我正在尝试构建一个 python 脚本,它需要一个特定的目录来创建一些文件。当我尝试使用“PyInstaller”构建应用程序时,它没有在 dist 中包含这个空的 “reports” 文件夹。所有其他包含文件的文件夹都正常包含在内。请注意,我没有使用 --onefile 命令,可执行文件本身位于文件夹内:dist/main/main.exe

我的 main.spec 文件

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None

added_files = [
         ( 'database/reports.sqlite', 'database' ),
         ( 'templates/*', 'templates' ),
         ( 'reports', 'reports' )
         ]

a = Analysis(['main.py'],
             pathex=['\\\\SRV\\Data\\pyi'],
             binaries=[],
             datas=added_files,
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             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,
          exclude_binaries=True,
          name='main',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=False )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               upx_exclude=[],
               name='main')

最佳答案

我遇到了与您相同的问题,我设法使用 PyInstaller 提供的 --add-data 选项将文件夹“复制”到输出。

请注意,我使用 PyInstaller 5.7.0 版在 Windows 10 机器上测试了此命令:

py -m PyInstaller --add-data "Logs;Logs" .\main.py

在 Linux 或其他操作系统上这应该可以工作:

pyinstaller --add-data "Logs:Logs" ./main.py

其中“Logs”是应用程序根目录中的一个文件夹,“main.py”文件所在的位置。

documentation 中所述,选项值在 Windows 上应采用 "SOURCE;DESTINATION" 形式,在大多数 Unix 系统上应采用 "SOURCE:DESTINATION" 形式。源可以是文件(例如 example.json)或文件夹。目标是“dist”文件夹中的实际路径,用于复制源(“.”将文件放在 dist 文件夹的根目录中)。

希望这对其他人有帮助! :)

关于python - Pyinstaller - 在 dist 中包含空文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59159300/

相关文章:

python - pyinstaller排除模块原因 "failed to execute script"

Python3 Selenium ChromeDriver 禁用扩展仅记录 Pyinstaller Windows 10

python - pyinstaller 不显示图像和图标

python - 替换 pandas 中两列的值

python - 读取一位操作python 2.6

python - matplotlib 中同一循环的两个不同图?

python - 限制对仅拥有的内容 django 的访问

python - django View 上的 NameError : name 'name' is not defined with request. POST.get

python-2.7 - 什么是sys._MEIPASS

python - PyInstaller 和 QML 文件