Python GUI2Exe Application Standalone Build (Using Py2Exe)

守給你的承諾、 提交于 2020-01-17 06:33:20

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/33683133/python-gui2exe-application-standalone-build-using-py2exe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!