【问题标题】:Bundling a standalone exe捆绑独立的 exe
【发布时间】:2016-11-26 03:17:20
【问题描述】:

所以,很长一段时间以来,我一直在尝试制作 Standalone EXE。现在我安装了 python 32 位,我尝试了py2exe,使用它的bundle_files 选项为我的项目comic-dl 制作一个exe。

由于comic-dl 有点像youtube-dl(甚至是该死的名字),所以在我无法让自己的setup.p 文件正常工作后,我复制了youtube-dls' setup.py file,然后将其修改为让它适用于我的项目。

Here is my modification。然后我运行这些命令:

python setup.py install python setup.py py2exe

一切顺利,我得到了一个comic-dl.exe (~6 MB)。但是,当我执行它时,我得到了这个错误:

Traceback (most recent call last):

  File "comic-dl.py", line 4, in <module>

  File "zipextimporter.pyo", line 82, in load_module

  File "honcho.pyo", line 12, in <module>

  File "zipextimporter.pyo", line 82, in load_module

  File "sites\mangafox.pyo", line 13, in <module>

  File "zipextimporter.pyo", line 82, in load_module

  File "selenium\webdriver\__init__.pyo", line 18, in <module>

  File "zipextimporter.pyo", line 82, in load_module

  File "selenium\webdriver\firefox\webdriver.pyo", line 39, in <module>

  File "zipextimporter.pyo", line 82, in load_module

  File "selenium\webdriver\remote\webdriver.pyo", line 25, in <module>

  File "zipextimporter.pyo", line 82, in load_module

  File "selenium\webdriver\remote\webelement.pyo", line 40, in <module>

  File "pkgutil.pyo", line 591, in get_data

IOError: [Errno 2] No such file or directory: 'selenium\\webdriver\\remote\\getAttribute.js'

我检查了 selenium 文件夹中的 getAttribute.js 文件,该文件就在那里。我什至在项目本身中复制了 selenium 的文件夹,仍然没有变化。

然后我尝试了this,但这没有任何意义,因为并非所有内容都捆绑在选项 3 中,当我更改选项并执行设置命令时,选项 2 对我来说似乎相同。

在这种情况下如何获取独立的 exe?

【问题讨论】:

  • 不要使用复杂的 py2exe,而是使用名为 nuitka 的简单 1 站式商店。它可以通过一个命令为您构建 exe 和 Linux 可执行文件。此外,它可以捆绑它而无需任何人弄清楚它实际上是 python。 (不需要音效)
  • 我试过没有运气。有什么我可以使用的吗?
  • Cx_freeze 是一个很好的项目。只是如果你想让它可移植,你必须打包一个目录。快速搜索可以为您提供大量有关如何使用它的教程
  • 我需要 1 个 exe。 cx_freeze 是我已经在使用的。 py2exe 将为我提供整个项目中的独立便携式 1 exe。这就是我正在看的。
  • 说实话,最后一个选择是使用 Cython。将你的python代码转换成C,然后编译成exe

标签: python selenium py2exe


【解决方案1】:

我也遇到了这个问题。这是我解决它的方法:

  1. 转到C:\Python27\selenium\webdriver\remote\ [如果 selenium 安装在其他目录中,目录可能会有所不同。本质是找到文件]。有getAttribute.jsIsDisplayed.js 文件。复制它们。
  2. 在您分发的dist 文件夹中,有一个library.zip 文件。解压缩或在 Windows 默认查看器中打开。
  3. 转到 selenium\webdriver\remote\ 并粘贴在步骤 1 中复制的文件。
  4. 如果您解压library.zip,请将其压缩并替换原来的。

它适用于我。希望这可以帮助你。

【讨论】:

    【解决方案2】:

    这是我的解决方案。希望能帮到你!

    第一步:修改文件webelement.py

    # customized code to resolve resources's path problem when executing py2exe executables
    import sys
    frozen = getattr(sys, 'frozen', '')
    if not frozen:
        getAttribute_js = pkgutil.get_data(__package__, 'getAttribute.js').decode('utf8')
        isDisplayed_js = pkgutil.get_data(__package__, 'isDisplayed.js').decode('utf8')
    else:
        approot = os.path.dirname(sys.executable)
        getAttribute_js = open(os.path.join(approot, 'getAttribute.js'), 'rb').read().decode('utf8')
        isDisplayed_js = open(os.path.join(approot, 'isDisplayed.js'), 'rb').read().decode('utf8')
    

    注意:在我的环境中,此文件位于 C:\Python27\Lib\site-packages\selenium\webdriver\remote。

    第 2 步:在您的 py2exe 的 setup.py 中,将所需文件包含到您的数据文件中。例如

    data_files = [(r'.', glob(r'C:\Python27\Lib\site-packages\selenium\webdriver\remote\getAttribute.js')),
        (r'.', glob(r'C:\Python27\Lib\site-packages\selenium\webdriver\remote\isDisplayed.js'))]
    

    然后你应该让你的 exe 工作。我已经在 Windows 7、32 位系统中对此进行了测试。 python 2.7,带有硒 3.0.2。

    【讨论】:

      【解决方案3】:

      看起来您可能必须在相对路径中设置可执行文件才能到达硬编码的文件位置。

      或者,我建议您使用PyInstaller,它在最好的情况下不需要任何配置,并且可以在一个命令中立即为您提供一个工作可执行文件。

      【讨论】:

      • 我已经尝试过 Pyinstaller。但是,由于某种原因,pyinstaller 不包含我的模块,因此 exe 似乎不起作用。
      • 不,与 pyinstaller 有同样的问题驱使我到这里
      【解决方案4】:

      为我工作

      • C:\Python27\selenium\webdriver\remote\有getAttribute.js和IsDisplayed.js文件。复制它们。
        • 将它们粘贴到 dist\selenium\webdriver\remote 而不是 zip 文件中。
        • 运行.exe
        • 利润

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-09-03
        • 1970-01-01
        • 1970-01-01
        • 2021-12-01
        • 2017-07-15
        • 2019-03-05
        • 2011-04-08
        • 2017-03-07
        相关资源
        最近更新 更多