【问题标题】:PyInstaller: IOError: [Errno 2] No such file or directory: with ciscoconfparse libraryPyInstaller: IOError: [Errno 2] No such file or directory: with ciscoconfparse library
【发布时间】:2018-06-04 12:59:51
【问题描述】:

我使用 pyinstaller 创建了我的 python 代码的 .exe,它运行良好。但是在导入这个特定的包“from ciscoconfparse import CiscoConfParse ",pyinstaller 能够创建 .exe,但是当我执行 .exe 时它会抛出错误消息

Please see this image link

我尝试了其他一些帖子中提到的解决方法,但似乎没有一个工作,这个问题只有在我使用 ciscoconfparse 模块时才会出现。

请帮助我如何解决这个问题,使用这个模块很重要。

【问题讨论】:

  • 根据回溯,我认为您需要添加 ciscoconfparse version 文件;见pythonhosted.org/PyInstaller/…
  • 感谢@AKX,我使用 C:\Python27\Scripts>pyi-makespec --onefile "RR Config Scrub_v1.py" 编写了 C:\Python27\Scripts\RR Config Scrub_v1 创建了一个规范文件。 spec 现在运行 pyinstaller.py 来构建可执行文件
  • # -- mode: python -- block_cipher = None a = Analysis(['RR Config Scrub_v1.py'], pathex=['C:\\Python27\ \Scripts'], binaries=[], datas=[('C:\Python27\Lib\site-packages\ciscoconfparse\version'), 'ciscoconfparse'], hiddenimports=[], hookspath=[], runtime_hooks=[ ], excludes=[], 我仍然得到同样的错误请指导在.exe中包含版本文件的确切步骤
  • 要生成一个文件到 exec ,你必须先 makespec : python Makespec.py --noconsole --onefile file.py ,然后你使用 Build.py : python Build.py file/file.py ,您将在 file/dist/file.exe 中找到您的文件
  • 真正的问题是我需要在规范文件中添加什么才能使其工作?根据文档创建一个新的规范文件是 pyi-makespec [--onefile] yourprogram.py ......我需要修改规范文件的哪一部分以便我可以继续进行。

标签: python-2.7 pyinstaller ciscoconfparse


【解决方案1】:

通过@AKX 访问此链接https://pythonhosted.org/PyInstaller/spec-files.html#adding-files-to-the-bundle

我创建了一个规范文件,并在规范文件中添加了这两行

         datas=[(  'C:\Python27\Lib\site-packages\ciscoconfparse\*', 'ciscoconfparse' ) ],
         hiddenimports=['ciscoconfparse'],

然后使用规范文件将其编译成 .exe

pyinstaller --clean -y --onefile "RR Config Scrub_v1.spec"

问题已解决

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-25
    • 2018-06-10
    • 1970-01-01
    • 2013-07-23
    • 2016-06-07
    相关资源
    最近更新 更多