【问题标题】:executable with py installer not runningpy安装程序未运行的可执行文件
【发布时间】:2020-02-09 06:13:39
【问题描述】:

在将 python 项目转换为可执行文件时出现的问题,我已经挣扎了太多小时。

由于对可执行文件不太熟悉,我假设我需要执行我的项目的 GUI 文件,但我真的很努力解决路径和所有问题,现在我所有的 8 个 python 脚本和 4 个 csv 文件都在同一个文件中目录。

运行 GUI.app 时(在使用 Include multiple data files with pyinstaller 建议的 pyinstaller 之后)文件不运行并且我收到错误:

FileNotFoundError: File b'items_pro_processing.csv' does not exist
[25005] Failed to execute script GUI
logout

但是,文件在那里!我所有的 python 脚本和 csv 文件都在同一个文件夹中。我已按如下方式修改了我的规范文件以包含所有 csv 文件:

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

block_cipher = None


a = Analysis(['GUI.py'],
             pathex=['/Users/pierre/Desktop/exx'],
             binaries=[],
             datas=[('EvenPlast_historical_data.csv', 'EvenPlast_historical_data.csv'),



('items_pro_processing.csv', 'items_pro_processing.csv'),
('parameters.csv', 'parameters.csv'),
('Supplier_list1.csv', 'Supplier_list1.csv')],
             hiddenimports=[items_pro_processing.csv'],
             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,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='GUI',
          debug=True,
          bootloader_ignore_signals=False,
          strip=False,
          upx=False,
          upx_exclude=[],
          runtime_tmpdir=None,
          console=True )

在这一点上,我不知道出了什么问题,我希望新的眼光可以解开这种局面。

更新:

正如 Barni 在Bundling data files with PyInstaller (--onefile) 中所建议的,我已将以下 sn-p 代码添加到我想要转换为 exe 的文件中。


def resource_path(relative_path):
    """ Get absolute path to resource, works for dev and for PyInstaller """
    if hasattr(sys, '_MEIPASS'):
        return os.path.join(sys._MEIPASS, relative_path)

    return os.path.join(os.path.abspath("."), relative_path)

for root, dirs, files in os.walk(resource_path("")):
    print(root)
    for file in files:
        print( "  ",file)

然后当我运行文件时,我得到了这个:

/Users/pierre/Desktop/exx/
   items_pro_processing.csv
   parameters.csv
   dsjkfb.py
   monthfor.py
   EvenPlast_historical_data.csv
   .DS_Store
   Supplier_list1.csv
   alerte_commande.py
   items_file_processing.py
   monthly_forecast.py
   daily_forecast.py
   ABCD_analysis_pre_processing.py
   GUI.spec
   GUI.py
   metrics_fournisseur.py
   replenishment_per_supplier.py
   value_analysis_all.py
/Users/pierre/Desktop/exx/dist
   GUI
/Users/pierre/Desktop/exx/dist/GUI.app
/Users/pierre/Desktop/exx/dist/GUI.app/Contents
   Info.plist
/Users/pierre/Desktop/exx/dist/GUI.app/Contents/MacOS
   GUI
/Users/pierre/Desktop/exx/dist/GUI.app/Contents/Resources
   icon-windowed.icns
/Users/pierre/Desktop/exx/dist/GUI.app/Contents/Frameworks
/Users/pierre/Desktop/exx/__pycache__
   daily_forecast.cpython-37.pyc
   alerte_commande.cpython-37.pyc
   ABCD_analysis_pre_processing.cpython-37.pyc
   replenishment_per_supplier.cpython-37.pyc
   metrics_fournisseur.cpython-37.pyc
   value_analysis_all.cpython-37.pyc
   GUI.cpython-37.pyc
   monthfor.cpython-37.pyc
   items_file_processing.cpython-37.pyc
   monthly_forecast.cpython-37.pyc
/Users/pierre/Desktop/exx/build
/Users/pierre/Desktop/exx/build/GUI
   Analysis-00.toc
   PKG-00.toc
   PYZ-00.toc
   base_library.zip
   warn-GUI.txt
   EXE-00.toc
   PYZ-00.pyz
   BUNDLE-00.toc
   xref-GUI.html
   Tree-00.toc
   Tree-01.toc
   PKG-00.pkg

我觉得它已经取得了进展,但我正在努力解释该输出,或者更像是如何处理它。

【问题讨论】:

  • 我对这个问题的回答中有一段代码,它将向您显示 pyinstaller 可执行文件中实际包含哪些文件,以及它们在哪里stackoverflow.com/questions/7674790/…
  • 问题不在于 PyInstaller,而是你的代码在 PyInstaller 可执行文件中运行时找不到它期望在某个位置的文件
  • 谢谢!和潜在的愚蠢问题我需要将代码的资源路径()sn-p放在哪里
  • 在与 sn-p 相同的文件中(应该在 main() 中运行)
  • 我已经这样做了,目的是为了知道将我的文件移动到哪里更正​​?我仍然有点困惑为什么如果它们都在同一个目录中它不起作用,并且我在代码中的“导入”都很好

标签: python


【解决方案1】:

我不知道这是否是复制/粘贴错误,但在您的行中

hiddenimports=[items_pro_processing.csv'],

你错过了'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-05
    • 1970-01-01
    • 1970-01-01
    • 2015-04-24
    相关资源
    最近更新 更多