【问题标题】:How does PyInstaller manage to create and EXE file when the python script is consisted of proprietary module?当 python 脚本由专有模块组成时,PyInstaller 如何管理创建和 EXE 文件?
【发布时间】:2017-12-14 07:12:54
【问题描述】:

您好,我有一个脚本,我想将其转换为 EXE 文件,以便您在我的开发环境之外使用它。 这个脚本使用了基于 selenium 的专有模块(在我的例子中是 firefox webdriver)。 我已使用 PyInstaller 将脚本 (CFP2_Recovery.py) 转换为 EXE 文件。这个转换的结果看起来不错:

C:\Users\alpha_2.PL\workspace\PacketLight Automation\Test_Cases\Experiment pyinstall>pyinstaller CFP2_Recovery.py
278 INFO: PyInstaller: 3.3
279 INFO: Python: 3.5.2
279 INFO: Platform: Windows-7-6.1.7601-SP1
285 INFO: wrote C:\Users\alpha_2.PL\workspace\PacketLightAutomation\Test_Cases\Experiment pyinstall\CFP2_Recovery.spec
293 INFO: UPX is not available.
299 INFO: Extending PYTHONPATH with paths
['C:\\Users\\alpha_2.PL\\workspace\\PacketLight '
 'Automation\\Test_Cases\\Experiment pyinstall',
 'C:\\Users\\alpha_2.PL\\workspace\\PacketLight '
 'Automation\\Test_Cases\\Experiment pyinstall']
299 INFO: checking Analysis
300 INFO: Building Analysis because out00-Analysis.toc is non existent
300 INFO: Initializing module dependency graph...
304 INFO: Initializing module graph hooks...
308 INFO: Analyzing base_library.zip ...
5411 INFO: running Analysis out00-Analysis.toc
6803 INFO: Caching module hooks...
6810 INFO: Analyzing C:\Users\alpha_2.PL\workspace\PacketLightAutomation\Test_Cases\Experiment pyinstall\CFP2_Recovery.py
8706 INFO: Loading module hooks...
8707 INFO: Loading module hook "hook-pydoc.py"...
8710 INFO: Loading module hook "hook-encodings.py"...
8895 INFO: Loading module hook "hook-selenium.py"...
8908 INFO: Loading module hook "hook-xml.dom.domreg.py"...
8910 INFO: Loading module hook "hook-xml.py"...
8937 INFO: Looking for ctypes DLLs
8973 INFO: Analyzing run-time hooks ...
8987 INFO: Looking for dynamic libraries
9440 INFO: Looking for eggs
9440 INFO: Using Python library c:\program files\python35\python35.dll
9441 INFO: Found binding redirects:
[]
9449 INFO: Warnings written to C:\Users\alpha_2.PL\workspace\PacketLightAutomation\Test_Cases\Experiment pyinstall\build\CFP2_Recovery\warnCFP2_Recovery.txt
9540 INFO: Graph cross-reference written to C:\Users\alpha_2.PL\workspace\Packet
Light Automation\Test_Cases\Experiment pyinstall\build\CFP2_Recovery\xref-CFP2_Recovery.html
9594 INFO: checking PYZ
9595 INFO: Building PYZ because out00-PYZ.toc is non existent
9595 INFO: Building PYZ (ZlibArchive) C:\Users\alpha_2.PL\workspace\PacketLightAutomation\Test_Cases\Experiment pyinstall\build\CFP2_Recovery\out00-PYZ.pyz
10469 INFO: Building PYZ (ZlibArchive) C:\Users\alpha_2.PL\workspace\PacketLightAutomation\Test_Cases\Experiment pyinstall\build\CFP2_Recovery\out00-PYZ.pyz completed successfully.
10487 INFO: checking PKG
10488 INFO: Building PKG because out00-PKG.toc is non existent
10488 INFO: Building PKG (CArchive) out00-PKG.pkg
10521 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
10525 INFO: Bootloader c:\program files\python35\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
10526 INFO: checking EXE
10526 INFO: Building EXE because out00-EXE.toc is non existent
10526 INFO: Building EXE from out00-EXE.toc
10527 INFO: Appending archive to EXE C:\Users\alpha_2.PL\workspace\PacketLightAutomation\Test_Cases\Experiment pyinstall\build\CFP2_Recovery\CFP2_Recovery.exe
10553 INFO: Building EXE from out00-EXE.toc completed successfully.
10560 INFO: checking COLLECT
10561 INFO: Building COLLECT because out00-COLLECT.toc is non existent
10562 INFO: Building COLLECT out00-COLLECT.toc
10828 INFO: Updating manifest in C:\Users\alpha_2.PL\AppData\Roaming\pyinstaller\bincache00_py35_64bit\python35.dll
10830 INFO: Updating resource type 24 name 2 language 1033
11862 INFO: Updating manifest in C:\Users\alpha_2.PL\AppData\Roaming\pyinstaller\bincache00_py35_64bit\_ssl.pyd
11864 INFO: Updating resource type 24 name 2 language 1033
11966 INFO: Updating manifest in C:\Users\alpha_2.PL\AppData\Roaming\pyinstaller\bincache00_py35_64bit\unicodedata.pyd
11968 INFO: Updating resource type 24 name 2 language 1033
12031 INFO: Updating manifest in C:\Users\alpha_2.PL\AppData\Roaming\pyinstaller\bincache00_py35_64bit\_ctypes.pyd
12033 INFO: Updating resource type 24 name 2 language 1033
12088 INFO: Updating manifest in C:\Users\alpha_2.PL\AppData\Roaming\pyinstaller\bincache00_py35_64bit\pyexpat.pyd
12090 INFO: Updating resource type 24 name 2 language 1033
12200 INFO: Updating manifest in C:\Users\alpha_2.PL\AppData\Roaming\pyinstaller\bincache00_py35_64bit\_hashlib.pyd
12202 INFO: Updating resource type 24 name 2 language 1033
12266 INFO: Updating manifest in C:\Users\alpha_2.PL\AppData\Roaming\pyinstaller\bincache00_py35_64bit\select.pyd
12268 INFO: Updating resource type 24 name 2 language 1033
12314 INFO: Updating manifest in C:\Users\alpha_2.PL\AppData\Roaming\pyinstaller\bincache00_py35_64bit\_bz2.pyd
12316 INFO: Updating resource type 24 name 2 language 1033
12369 INFO: Updating manifest in C:\Users\alpha_2.PL\AppData\Roaming\pyinstaller\bincache00_py35_64bit\_lzma.pyd
12371 INFO: Updating resource type 24 name 2 language 1033
12424 INFO: Updating manifest in C:\Users\alpha_2.PL\AppData\Roaming\pyinstaller\bincache00_py35_64bit\_socket.pyd
12426 INFO: Updating resource type 24 name 2 language 1033
13510 INFO: Building COLLECT out00-COLLECT.toc completed successfully.

我将脚本转换的全部内容复制到其他站并尝试运行它。该脚本几乎立即失败了,我相信这是在 selenium 和我的私人图书馆参与其中的部分。这是我尝试运行 EXE 文件的结果:

C:\Users\alpha_3\Desktop\CFP2_Recovery\dist\CFP2_Recovery>CFP2_Recovery.exe
Please enter a valid DUT's IP: 10.0.1.134
Starting Cycle 1
17:30:02 13-12-2017

Traceback (most recent call last):
  File "site-packages\selenium\webdriver\common\service.py", line 74, in start
  File "subprocess.py", line 947, in __init__
  File "subprocess.py", line 1224, in _execute_child
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "Test_Cases\Experiment pyinstall\CFP2_Recovery.py", line 92, in <module>
  File "Test_Cases\Experiment pyinstall\CFP2_Recovery.py", line 42, in main
  File "Utilities\Browser_Utils.py", line 9, in Open_Browser
  File "site-packages\selenium\webdriver\firefox\webdriver.py", line 142, in __init__
  File "site-packages\selenium\webdriver\common\service.py", line 81, in start
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.

[3040] Failed to execute script CFP2_Recovery

我不知道到底是什么问题,但错误消息中的一行引起了我的注意。告诉“ 'geckodriver' 可执行文件需要在 PATH 中”的那个。 geckodriver(firefox webdriver)实际上是在开发站的PATH中。 我是否也应该将它放在我试图从中运行(EXE 文件)的工作站的 PATH 中? 我在创建 EXE 文件的过程中遗漏了什么吗?

【问题讨论】:

标签: python selenium selenium-webdriver pyinstaller


【解决方案1】:

你的代码中有这样的东西吗:

browser = webdriver.Firefox(executable_path=r"geckodriver-v0.19.1-win64\geckodriver.exe")

也许您可以将 geckodriver 打包到您的安装路径中。

【讨论】:

  • 你说我应该在我的安装路径中打包 geckodriver 是什么意思?我该怎么做?
  • @moshe-s 将“geckodriver-v0.19.1-win64.zip”(假设您使用的是 64 位版本)解压缩到 dist// ...对我有用。
  • 我相信事实并非如此。我设法在用于开发脚本的工作站中运行相同的脚本。但是,当我尝试创建 EXE 文件并在甚至没有基本 python 安装的工作站中运行它时,我设法开始运行脚本,但在我需要开始在浏览器上执行自动操作时失败了
  • @moshe-s 你没有详细说明你是如何在另一个站跑的?只取exe文件当然行不通。在您的设置和目标站之间,您可能需要考虑一些因素。希望这可以帮助。您最初的问题是 'geckodriver' 可执行文件需要位于 PATH " 中,我已经为您提供了如何包含它的答案。如果您现在遇到其他问题,希望您能提供详细信息跨度>
  • 我也有同样的错误。我所做的是在使用上面给出的代码调用 webdriver 时添加了相对路径。所以我建议(1)你也可以这样做。 (2) 然后使用您的 exe 将 geckodriver 解压缩到文件夹中,因为您现在使用的是相对路径。示例:C:\Test\ 是包含您的可执行文件和所有必需文件的文件夹。然后提取 gecko 驱动程序,使其位于 C:\Test\geckodriver-v0.19.1-win64\geckodriver.exe 中。当然,您应该在本地机器上测试验证步骤 (1)。
猜你喜欢
  • 1970-01-01
  • 2015-08-24
  • 2021-10-21
  • 2022-06-19
  • 1970-01-01
  • 2020-05-07
  • 1970-01-01
  • 1970-01-01
  • 2021-03-05
相关资源
最近更新 更多