使用 Selenium 模块创建一个 Exe:Py2exe/Pyinstaller [英] Creating an Exe with Selenium Module: Py2exe/Pyinstaller

查看:43
本文介绍了使用 Selenium 模块创建一个 Exe:Py2exe/Pyinstaller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到处找.Stackoverflow、各种留言板、py2exe 网站、pyinstaller 网站……没有任何帮助.包括 selenium 模块,特别是制作一个支持 firefox 的 exe,似乎是不可能的.我开始拔毛了,因为使用 py2exe 和 pyinstaller 变得非常头疼.

I've looked everywhere. Stackoverflow, various messageboards, the py2exe website, the pyinstaller website...nothing is helping. Including the selenium module, particularly making an exe that supports firefox, seems impossible. I am starting to pull out my hair because using either py2exe and pyinstaller is becoming a huge headache.

py2exe 和 pyinstaller 都有各自的问题.

Both py2exe and pyinstaller have their share of problems.

我的目标是制作一个单独的exe文件,没有任何额外的目录,这样其他人如果没有python/模块也可以使用我的程序.

My goal is to make one single exe file, without any extra directories, so that other people can use my program if they do not have python/modules.

使用 py2exe,如果我创建一个 setup.py 文件

With py2exe, if I create a setup.py file as such

from distutils.core import setup
import py2exe

setup(
name='Ask Alfred',
data_files = [('Drivers', ['Drivers/chromedriver.exe',
             'Drivers/webdriver.xpi','Drivers/webdriver_prefs.json'])],
version='1.0',
description='Find emails fast!',
author='Me',
windows=[{'script': 'alphy.py'}],
options={
    'py2exe':
        {
            'skip_archive': False,
            'optimize': 2,
        }
}
)

它将在 dist 文件夹和 Drivers 文件夹中创建一个包含我需要的文件的 exe,但是,如果我尝试运行该 exe,它会告诉我它找不到这些文件(因为它正在library.zip 文件夹).最重要的是,我的 GUI 看起来很糟糕(字体现在是灰色而不是黑色,白色背景的图像现在是灰色背景).

it will create an exe in the dist folder and a Drivers folder with the files I need, however, if I try to run the exe it will tell me that it could not find these files (because it is looking for them in the library.zip folder). On top of that, my GUI looks terrible (fonts are now grey instead of black and images with white backgrounds now have grey backgrounds).

使用 pyinstaller,如果我在创建 exe 时使用--onefile"标志,它根本不起作用/firefox 和 chrome 都不会启动.

With pyinstaller, if I use the "--onefile" flag when creating the exe it does not work at all/neither firefox nor chrome gets started.

如果我选择不存档/不制作一个文件,我只会得到可行的结果.在这种情况下,pyinstaller 提供了一个完整的解决方案.

With either, I only get workable results if I choose to not archive/not make one file. In that case, pyinstaller delivers a fully working solution.

推荐答案

试试这个:

options={
    'py2exe':
        {
            'skip_archive': True,
            'unbuffered': True,
            'bundle_files': 2, #assuming you dont want to include the python interpreter
            'optimize': 2,
        },
},
zipfile = None

这篇关于使用 Selenium 模块创建一个 Exe:Py2exe/Pyinstaller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆