Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何为selenium web驱动程序中创建的.py文件创建.exe?_Python_Selenium_Py2exe_Pyinstaller - Fatal编程技术网

Python 如何为selenium web驱动程序中创建的.py文件创建.exe?

Python 如何为selenium web驱动程序中创建的.py文件创建.exe?,python,selenium,py2exe,pyinstaller,Python,Selenium,Py2exe,Pyinstaller,到目前为止,我已经使用了Py2exe,但不确定如何添加与firefox和我在脚本中使用的其他导入包相关的selenium web驱动程序依赖项 我还研究了Pyinstaller,但它在添加依赖项时失败 我是第一次这样做,所以请建议如何正确地做 谢谢您可能想尝试CX\u Freeze,它添加了代码作为单个.exe运行所需的所有必要包/依赖项 pip install cx_Freeze 您可能想尝试CX_Freeze,它会添加代码作为单个.exe运行所需的所有必要包/依赖项 pip install

到目前为止,我已经使用了Py2exe,但不确定如何添加与firefox和我在脚本中使用的其他导入包相关的selenium web驱动程序依赖项

我还研究了Pyinstaller,但它在添加依赖项时失败

我是第一次这样做,所以请建议如何正确地做


谢谢

您可能想尝试CX\u Freeze,它添加了代码作为单个.exe运行所需的所有必要包/依赖项

pip install cx_Freeze

您可能想尝试CX_Freeze,它会添加代码作为单个.exe运行所需的所有必要包/依赖项

pip install cx_Freeze

您可以使用py2exe将python脚本打包为独立的可执行文件

默认情况下,py2exe打包所有导入的包。如果您还想打包浏览器,则可能必须使用便携式浏览器

您可以将便携式浏览器作为数据添加到py2exe包中,并在初始化webdriver时指定实际路径

您可以在下面的类中使用
executable\u path
参数指定firefox二进制可执行文件

webdriver.Firefox(self, firefox_profile=None,firefox_binary=None, timeout=30, capabilities=None, proxy=None, executable_path=geckodriver,  firefox_options=None, log_path=geckodriver.log)  

**我没有添加注释的选项,所以只能作为答案编写。

您可以使用py2exe将python脚本打包为独立的可执行文件

默认情况下,py2exe打包所有导入的包。如果您还想打包浏览器,则可能必须使用便携式浏览器

您可以将便携式浏览器作为数据添加到py2exe包中,并在初始化webdriver时指定实际路径

您可以在下面的类中使用
executable\u path
参数指定firefox二进制可执行文件

webdriver.Firefox(self, firefox_profile=None,firefox_binary=None, timeout=30, capabilities=None, proxy=None, executable_path=geckodriver,  firefox_options=None, log_path=geckodriver.log)  

**我没有添加注释的选项,所以只能作为答案写入。

您需要在setup.py文件中指定selenium webdriver的位置

以下代码应该有帮助:

from distutils.core import setup
import py2exe

# Change the path in the following line for webdriver.xpi
data_files = [('selenium/webdriver/firefox', ['C:/Python27/Lib/site-packages/selenium/webdriver/firefox/webdriver.xpi'])]

setup(
    name='Name of app',
    version='1.0',
    description='Description of app',
    author='author name',
    author_email='author email',
    url='',
    windows=[{'script': 'test.py'}],   # the main py file
    data_files=data_files,
    options={
        'py2exe':
            {
                'skip_archive': True,
                'optimize': 2,
            }
    }
)

您需要在setup.py文件中指定selenium webdriver的位置

以下代码应该有帮助:

from distutils.core import setup
import py2exe

# Change the path in the following line for webdriver.xpi
data_files = [('selenium/webdriver/firefox', ['C:/Python27/Lib/site-packages/selenium/webdriver/firefox/webdriver.xpi'])]

setup(
    name='Name of app',
    version='1.0',
    description='Description of app',
    author='author name',
    author_email='author email',
    url='',
    windows=[{'script': 'test.py'}],   # the main py file
    data_files=data_files,
    options={
        'py2exe':
            {
                'skip_archive': True,
                'optimize': 2,
            }
    }
)
您可以使用或创建python脚本/应用程序的可执行文件

pyinstaller的命令:

pyinstaller.exe --onefile --windowed <python file name>
pyinstaller.exe--一个文件--已打开窗口
您可以使用或创建python脚本/应用程序的可执行文件

pyinstaller的命令:

pyinstaller.exe --onefile --windowed <python file name>
pyinstaller.exe--一个文件--已打开窗口

Hi,我试过了,但不知怎么的,它没有添加firefox驱动程序,exe或msi也无能为力,有没有明确添加的方法?它不会添加firefox驱动程序,因为它不是Python模块/软件包。只要安装了firefox驱动程序,您就不会有问题,但如果您确实需要随它一起分发,请查看InnoSetup。谢谢,我再次尝试了它,并构建了exe,当我尝试双击exe时,它什么也不做。我也试着以管理员的身份运行它。我还建立了msi,我可以安装msi,但在程序文件上,同样的问题。exe不做任何事情。嗨,我尝试了这个,但不知怎么的,它没有添加firefox驱动程序,exe或msi不能做任何事情,有没有明确添加的方法?它不会添加firefox驱动程序,因为它不是Python模块/软件包。只要安装了firefox驱动程序,您就不会有问题,但如果您确实需要随它一起分发,请查看InnoSetup。谢谢,我再次尝试了它,并构建了exe,当我尝试双击exe时,它什么也不做。我也试着以管理员的身份运行它。我还建立了msi,我可以安装msi,但在程序文件相同的问题。exe不做任何事情。感谢您的回应,这样我可以创建exe,但得到一些消息如下,当我试图执行exe它什么也不做。以下模块似乎缺少['Carbon'、'Carbon.Files'、'u scproxy'、'u sysconfigdata'、'urlib.parse'、'winreg.CloseKey'、'winreg.HKEY\u CURRENT\u USER'、'winreg.HKEY\u LOCAL\u MACHINE'、'winreg.OpenKey'、'winreg.QueryValue'、'winreg.QueryValue']***二进制依赖项***可执行文件***还取决于这些未包含的DLL,您可能需要也可能不需要分发它们。如果分发其中任何文件,请确保您拥有许可证,并确保您不分发属于操作系统的文件。OLEAUT32.dll-C:\WINDOWS\system32\OLEAUT32.dll USER32.dll-C:\WINDOWS\system32\USER32.dll SHELL32.dll-C:\WINDOWS\system32\SHELL32.dll KERNEL32.dll-C:\WINDOWS\system32\KERNEL32.dll ADVAPI32.dll-C:\WINDOWS\system32\ADVAPI32.dll WS2\U 32.dll-C:\WINDOWS\system32\WS2\U 32.dll感谢您的回复,通过这种方式,我可以创建exe,但下面有一些消息,当我试图执行exe时,它什么也不做。以下模块似乎缺少['Carbon'、'Carbon.Files'、'u scproxy'、'u sysconfigdata'、'urlib.parse'、'winreg.CloseKey'、'winreg.HKEY\u CURRENT\u USER'、'winreg.HKEY\u LOCAL\u MACHINE'、'winreg.OpenKey'、'winreg.QueryValue'、'winreg.QueryValue']***二进制依赖项***可执行文件***还取决于这些未包含的DLL,您可能需要也可能不需要分发它们。如果分发其中任何文件,请确保您拥有许可证,并确保您不分发属于操作系统的文件。OLEAUT32.dll-C:\WINDOWS\system32\OLEAUT32.dll USER32.dll-C:\WINDOWS\system32\USER32.dll SHELL32.dll-C:\WINDOWS\system32\SHELL32.dll KERNEL32.dll-C:\WINDOWS\system32\KERNEL32.dll ADVAPI32.dll-C:\WINDOWS\system32\ADVAPI32.dll WS2\U 32.dll-C:\WINDOWS\system32\WS2\U 32.dll