Python - 构建可执行文件时遇到问题

发布于 2024-12-08 15:19:51 字数 490 浏览 0 评论 0原文

我是一名 python 程序员,我正在尝试构建一个可执行二进制文件来将我的软件分发给我的客户,即使它不是完全可执行的,我希望能够以一种方便最终的方式分发我的软件用户。

我已经尝试过 PyInstaller 和 Py2Exe,并且我在使用特定软件时遇到了同样的问题。

我在我的程序中使用了 splinter 模块(这当然是一个新的高级框架,用于与 Selenium 等其他框架交互),每次我尝试编译它时,似乎总会留下一个名为“webdriver.xpi”的文件从最终的包中出来,因此当程序尝试执行网络驱动程序时,它会失败并出现 IO 错误,指出未找到文件“webdriver.xpi”....但除此之外,GUI 和一切都工作得很好。

那么有没有办法手动包含它呢?我尝试通过浏览到特定文件夹@library.zip 文件来手动包含它,但它不起作用。

我在这方面并不是真正的专家,我依靠 GUI2Exe 来构建一切......如果可能的话,我真的很感激一些关于如何解决这个问题的建议。

谢谢。

I'm a python programmer and I'm trying to build an executable binary to distribute my software to my clients, even if it's not fully executable I want to be able to distribute my software in a way so that it is convenient for the end user.

I have already tried PyInstaller as well as Py2Exe and I'm facing the same problem with a particular software.

I used the splinter module for my program (which of course is a new high level framework to interact with other frameworks like Selenium) and every time I try to compile it there seems to be a file called "webdriver.xpi" that is always left out from the final package and therefore when the program attempts to execute the web-driver it fails with an IO Error saying that the file "webdriver.xpi" was not found....but other than that the GUI and everything works perfectly fine.

So is there a way to include it even manually? I tried including it manually by browsing to the specific folder @ library.zip file but it didn't work.

I'm not really expert in this matter and I rely on GUI2Exe for building everything...and I would really appreciate some advice if possible on how to fix this.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

人事已非 2024-12-15 15:19:51

我一整天都在研究这个问题,找到了一个解决方法,虽然很偷偷摸摸,但很有效。在我收到的错误消息中,我注意到库 .zip 之间有一个空格。我无法在 py2exe 或 selenium 的源代码中追踪它。我也尝试过将 xpi 文件放入库 zip 中,但没有成功。解决方法是:

  1. 在您的安装文件中使用以下选项:

    <前><代码>设置(
    console=['yourFile.py'],
    选项={
    “py2exe”:{
    “skip_archive”:正确,
    “无缓冲”:正确,
    “优化”:2
    }
    }

  2. 运行 py2exe 安装

  3. 将 xpi 文件复制到 dist 目录

即可。

I was at this all day and found a workaround, it's sneaky but it works. In the error message I was receiving I noticed that there was a space between in library .zip. I could not trace it down in the source code for py2exe or selenium. I too had tried putting the xpi file in the library zip and it did not work. The workaround is:

  1. In your setup file use these options:

    setup(
        console=['yourFile.py'],
        options={
                "py2exe":{
                        "skip_archive": True,
                        "unbuffered": True,
                        "optimize": 2
                }
        }
    )
    
  2. Run the py2exe install

  3. Copy the xpi file into the dist directory

That should do it.

心凉怎暖 2024-12-15 15:19:51

您需要在 setup.py 中提供指令,以将所有资源文件包含在您的发行版中。有几种方法可以做到这一点(请参阅 distutils、setuptools、distribute - 取决于您用来构建发行版的内容),但是 py2exe wiki 有一个示例

如果要安装资源,您可能需要使用此 py2exe 提示来查找资源到与您的 exe 相同的目录中。

有关一些其他信息,请参阅此答案有关在您的发行版中包含资源文件的信息。

You need an instruction in your setup.py to include any resource files in your distribution. There is a couple of ways of doing this (see distutils, setuptools, distribute - depending on what you are using to build your distribution), but the py2exe wiki has an example.

You may need to use this py2exe tip to find your resources if you're installing them into the same directory as your exe.

See this answer for some additional info on including resource files in your distribution.

挽心 2024-12-15 15:19:51

这是您问题的解决方案:
我稍微修改了代码,它应该可以工作,因为我遇到了同样的问题并且解决了它:

from distutils.core import setup
import py2exe

wd_base = 'C:\\Python27\\Lib\site-packages\\selenium-2.44.0-py2.7.egg    \\selenium\\webdriver'
RequiredDataFailes = [
('selenium/webdriver/firefox', ['%s\\firefox\\webdriver.xpi'%(wd_base), '%s\\firefox\\webdriver_prefs.json'%(wd_base)])
]

setup(
windows=[{"script":"gui_final.py"}],options={"py2exe":{"skip_archive": True,"includes":["sip"]}},
data_files=RequiredDataFailes,

)

Here is a solution of your question:
I have modify a code little and it should be work since I had a same issue and I solved it:

from distutils.core import setup
import py2exe

wd_base = 'C:\\Python27\\Lib\site-packages\\selenium-2.44.0-py2.7.egg    \\selenium\\webdriver'
RequiredDataFailes = [
('selenium/webdriver/firefox', ['%s\\firefox\\webdriver.xpi'%(wd_base), '%s\\firefox\\webdriver_prefs.json'%(wd_base)])
]

setup(
windows=[{"script":"gui_final.py"}],options={"py2exe":{"skip_archive": True,"includes":["sip"]}},
data_files=RequiredDataFailes,

)
泛泛之交 2024-12-15 15:19:51

我知道这已经过时了,但我想给出更新的答案,以避免建议程序员手动执行某些操作。

有一个 py2exe 选项可将数据文件列表指定为元组。 (pathtocopyto, [文件列表以及获取位置])

示例:

from disutils.core import setup
import py2exe

wd_base = 'C:\\Python27\\Lib\\site-packages\\selenium\\webdriver'
RequiredDataFailes = [
    ('selenium/webdriver/firefox', ['%s\\firefox\\webdriver.xpi'%(wd_base), '%s\\firefox\\webdriver_prefs.json'%(wd_base)])
]

setup(
    console=['MyScript.py'],
    data_files=RequiredDataFiles,
    options={
        **mypy2exeopts
    }
)

我目前知道的唯一缺点是您仍然需要 skip_archive = True。有一些解决方法可以获取library.zip中的数据文件,但我对网络驱动程序的信息没有太多运气。

I know this is old, but I wanted to give an updated answer to avoid suggesting that programmers do something manually.

There is a py2exe option to specify a list of data files as tuples. (pathtocopyto, [list of files and where to get them])

Example:

from disutils.core import setup
import py2exe

wd_base = 'C:\\Python27\\Lib\\site-packages\\selenium\\webdriver'
RequiredDataFailes = [
    ('selenium/webdriver/firefox', ['%s\\firefox\\webdriver.xpi'%(wd_base), '%s\\firefox\\webdriver_prefs.json'%(wd_base)])
]

setup(
    console=['MyScript.py'],
    data_files=RequiredDataFiles,
    options={
        **mypy2exeopts
    }
)

The only downside I am aware of currently is that you still need skip_archive = True. There are workarounds to get the data files in the library.zip, but I haven't had much luck with the webdriver's info.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文