0

我正在尝试将 Python 脚本构建到独立的应用程序中。我正在使用 GUI2Exe。我的脚本使用 selenium 包。我已经安装了。项目编译良好并直接在 python 命令行上运行,但无法独立构建,因为它指的是文件夹:

 ERROR: test_file_data_extract (__main__.FileDataExtract)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
 File "File_data_extract.py", line 18, in setUp
  File "selenium\webdriver\firefox\firefox_profile.pyc", line 63, in     __init__
 IOError: [Errno 2] No such file or directory: 'C:\\users\\username\\PycharmProjects\\Python_27_32bit\\file_data_extract\\dist\\File_data_extract.exe\\selenium\\webdriver\\firefox\\webdriver_prefs.json'

它正在寻找硒包位于:C:\Users\username\Anaconda2_Py27_32bit\Lib\site-packages\selenium-2.48.0-py2.7.egg\selenium\webdriver\firefox

其中 C:\Users\username\Anaconda2_Py27_32bit 是我安装 Anaconda Python 2.7 32 位版本的位置。默认情况下,它在 \dist\filename.exe 文件夹中查找。

4

1 回答 1

0

我能够使用 bbfreeze 构建它。它工作得很好。

首先,我必须通过 pip 安装 bbfreezee(仅限一次):

pip install bbfreeze

创建一个 build_package.py 文件:

from bbfreeze import Freezer
f = Freezer("project_name", includes=("selenium","SendKeys",)) #list problem packages here to manually include
f.addScript("project_name_script.py")
f()    # starts the freezing process

构建项目:

python build_package.py bdist_bbfreezee

在 project_name_script.py 所在的文件夹 project_name 中,您可以找到 project_name_script.exe 以及所有包含包,包括 selenium 和 sendkeys。当您分发包时,您需要分发整个 project_name,因为它包含所有依赖库 dll(python .pyd)。

更多详细信息请参阅此处的官方 bbfreezee: https ://pypi.python.org/pypi/bbfreeze/#downloads

于 2015-11-13T19:53:27.600 回答