简体   繁体   中英

Python GUI2Exe Application Standalone Build (Using Py2Exe)

I am trying to build a Python Script into a stand alone application. I am using GUI2Exe. My script uses selenium package. I have it installed. Project compiles fine and runs on python command line directly but fails to build a stand alone because it is referring to folder:

 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'

It is looking for selenium package is located at : C:\\Users\\username\\Anaconda2_Py27_32bit\\Lib\\site-packages\\selenium-2.48.0-py2.7.egg\\selenium\\webdriver\\firefox

where C:\\Users\\username\\Anaconda2_Py27_32bit is where I installed Anaconda Python 2.7, 32 bit version. By default it is looking for in \\dist\\filename.exe folder.

I was able to build it using bbfreeze. It works great.

First I had to install bbfreezee via pip (one time only):

pip install bbfreeze

Create a build_package.py file as:

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

Build project:

python build_package.py bdist_bbfreezee

in folder project_name where project_name_script.py sits you find project_name_script.exe with all the include packages including selenium and sendkeys. When you distribute the package you need to distribute entire project_name because it contains all dependent library dlls (python .pyd).

More details refer official bbfreezee here: https://pypi.python.org/pypi/bbfreeze/#downloads

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM