0

Hi I have a script that I want to turn into an EXE file so that I could you use it out of my Development Environment. This script is utilizing proprietary modules that are based on selenium (in my case firefox webdriver). I have converted the script (CFP2_Recovery.py) into an EXE file by using PyInstaller. The result of this conversion looks good:

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.

I copied the whole contents of the script conversion to the other station and tried to run it. The script almost immediately failed and I believe that it was during the part where selenium and my private libraries are getting involved. This is the result of me trying to run the EXE file:

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

I don't see what is the problem exactly but one of the lines in the error message got my eye. The one that tells that " 'geckodriver' executable needs to be in PATH ". geckodriver (firefox webdriver) is actually in PATH of the development station. Should I also puy it in PATH of the station that I am trying to run (EXE file) it from ? Am I missing something in the process of the EXE file creation ?

Moshe S.
  • 2,834
  • 3
  • 19
  • 31
  • Possible duplicate of [Running pyinstaller another pc with Chromedriver](https://stackoverflow.com/questions/47690548/running-pyinstaller-another-pc-with-chromedriver) – Florent B. Dec 14 '17 at 10:45

1 Answers1

0

Do you have something like this in your code:

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

Maybe you could package the geckodriver in your install path.

Javed Karim
  • 187
  • 1
  • 3
  • What do you mean when you say that I should package the geckodriver in my install path ? How do I do that ? – Moshe S. Dec 14 '17 at 10:48
  • @moshe-s Unzip the "geckodriver-v0.19.1-win64.zip" (assuming you're using the 64-bit ver) to **dist//** ... works for me. – Javed Karim Dec 15 '17 at 04:12
  • I believe that this is not the case. I manage to run the same script in the station that I use for developing the script. But, when I tried to create the EXE file and run it in a station that doesn't even have a basic python installation I managed to start running the script and failed at the point that I needed to start performing automatic actions on the Browser – Moshe S. Dec 17 '17 at 06:53
  • @moshe-s you didn't provide details how you ran on the other station? just taking the exe file will of course not work. There are a few factors you might need to look into between your setup and the target station. Hope this helps. Your original question was **'geckodriver' executable needs to be in PATH "** which I've given you the answer how to include it. If now you're encountering other problems, hope you could provide details – Javed Karim Dec 18 '17 at 04:02
  • First of all thank you very much for trying to help. I know that my question looks too long but it holds all the required details to understand the picture. I will try to sum it up. In my case I have a script which imports proprietary modules (my modules) and some other standard modules. By the way I am using selenium and specifically firefox webdriver in my automated test (the script). After I tried to convert my python script to an EXE file (by using pyinstaller) I copied all the files that pyinstaller created to a station which doesn't have any of the files (modules or webdriver) installed – Moshe S. Dec 20 '17 at 06:44
  • on it. Then I tried to run the EXE file (with the name of the original script) and the result is indicated above) – Moshe S. Dec 20 '17 at 06:45
  • 1
    I too had the same error. What I did was addd relative path when calling the webdriver with the code given above. So I would suggest (1) you can do the same. (2) Then extract the geckodriver to the folder with your exe since you're now using relative path. Example: C:\Test\ is the folder containg your executable and all required files. Then extract gecko driver such that it's in C:\Test\geckodriver-v0.19.1-win64\geckodriver.exe. Of course you should test verify step (1) on your local machine. – Javed Karim Dec 21 '17 at 01:38