i wrote a BOT for a webgame, works perfectly when i run it with IDLE, firefox launches and does the job. But after compiling with Py2exe firefox doesn't launch anymore...Any ideas ?
PS : Firefox 45.0.2 , Selenium 2.53
Hum finally i solved it, was my mistake, i was copying th wedriver.xpi and webdriver_prefs.json in the wrong directory...
So you need to compile it without making a Zipfile (or won't work) and copy the 2 files in the good directory :
from : C:\Python27\Lib\site-packages\selenium\webdriver\firefox
to : /dist/selenium/webdriver/firefox
Setup.py example:
from distutils.core import setup
import py2exe
setup(
name='Web BOT',
version='1.0',
description='BOT',
author='Author',
author_email='mymail#mail.com',
url='',
windows = [{
"script":"Myscript.py",
"icon_resources": [(1, "myicon.ico")],
}],
options={
'py2exe':
{
'skip_archive': True,
'optimize': 2,
}
}
)
And then everything works fine !
Related
I have a python program I've created and turned into an exe with cx_freeze. When just creating the exe with "python setup.py build", everything works great. Now I am trying to create an installer for it by using "python setup.py bdist_msi" and everything seems to work great at first.
The installer pops up and asks me to select a directory. After clicking next, Windows requires me to accept that I'm installing from an unknown publisher. After accepting, the next page immediately jumps to "Completing the (program) installer", and "click finish to exit the installer". After clicking finish, I cannot find my program file anywhere, and the installer appeared to do nothing.
I've tried running this on multiple computers, and nothing seems to work. I think this is an issue with my setup.py script. This does include several qml files and some pictures in my "Resources" folder, and there are several csv's in my "Data-and-executable" folder, plus a exe that is called on by my python script.
from cx_Freeze import setup, Executable
# dependencies
build_exe_options = {
"packages": ['atexit', "os", "sys", "csv", "time", "functools", "PySide2.QtCore", "PySide2.QtWidgets", "PySide2.QtUiTools", "PySide2.QtQuick", "PySide2.QtQml", "PySide2.QtGui", "shiboken2"],
"include_files": ['README.md', r'Resources','inputClass.py', 'selections.py','simulationOutput.py',
'Data-and-executable'],
"include_msvcr": True,
"excludes": ["Tkinter", "Tkconstants", "tcl", ],
"build_exe": "build",
}
bdist_msi_options = {
'add_to_path': False,
'initial_target_dir': r'[ProgramFilesFolder]\%s\%s' % ("Name", "Product"),
}
executable = [
Executable("main.py",
base="Win32GUI",
targetName="product.exe",
icon= r"Resources\logo_icon.ico"
)
]
setup(name = "Product",
version = "0.3",
description = "Simulator",
options={"bdist_msi": bdist_msi_options,
"build_exe": build_exe_options},
executables=executable
)
There are no error messages or anything else to tip me off as to what's going on. Even calling my .msi with cmd does not provide any insight.
Smh. I had all of my files just in the "build" folder, and not the "build/exe.win-amd64-3.6" folder. It works.
So far I have used Py2exe but not sure how to add selenium web driver dependencies related to firefox and other import package I used in my script.
I also explored Pyinstaller but it failed on adding dependencies.
I am doing it for the first time so please suggest how to do it properly.
Thank You
You can use py2exe to pack your python script as a standalone executable.
By default py2exe packs all imported packages. If you want to pack browser also, you might have to use portable browser.
You can add portable browser as data to your py2exe package and specify the realative path while initializing webdriver.
You can specify firefox binary executable using executable_path argument in below class.
webdriver.Firefox(self, firefox_profile=None,firefox_binary=None, timeout=30, capabilities=None, proxy=None, executable_path=geckodriver, firefox_options=None, log_path=geckodriver.log)
** I dont have option to add comment , so writing as answer.
You need to specify the location of selenium webdriver in setup.py file.
Following code should help:
from distutils.core import setup
import py2exe
# Change the path in the following line for webdriver.xpi
data_files = [('selenium/webdriver/firefox', ['C:/Python27/Lib/site-packages/selenium/webdriver/firefox/webdriver.xpi'])]
setup(
name='Name of app',
version='1.0',
description='Description of app',
author='author name',
author_email='author email',
url='',
windows=[{'script': 'test.py'}], # the main py file
data_files=data_files,
options={
'py2exe':
{
'skip_archive': True,
'optimize': 2,
}
}
)
You may want to try CX_Freeze,it adds all necessary packages/dependencies required for your code to run as a single .exe
pip install cx_Freeze
You can use pyinstaller or cx_freeze to create executable files of python scripts/applications.
Command of pyinstaller:
pyinstaller.exe --onefile --windowed <python file name>
I am trying to make a single executable out of my application that uses matplotlib using Python 2.7 and py2exe. So, I have this standard routine:
from distutils.core import setup
import zmq.libzmq
import py2exe
import glob
import matplotlib
import shutil
ico_file = "C:/Users/MyPC/Documents/newIcon.ico"
setup( windows = [{
"script":"myApp.py",
"icon_resources": [(1, ico_file)]
}],
options={
'py2exe': {
'includes':['zmq.backend.cython',
'scipy.special._ufuncs_cxx',
'scipy.linalg.cython_blas',
'scipy.linalg.cython_lapack',
'scipy.sparse.csgraph._validation'],
'excludes':['zmq.libzmq'],
'dll_excludes':['libzmq.pyd'],
'bundle_files': 2,
'compressed': True
}
},
zipfile=None,
data_files=[ ('lib', (zmq.libzmq.__file__,), ico_file) ] + matplotlib.get_py2exe_datafiles()
)
Problem Definition The created file, myApp.exe, does not run after double clicking on it (or calling from cmd). So, I used Dependency walker and I can see that zlip.pyd is missing:
LoadLibraryA("c:\users\mypc\documents\myapp\bin\dist\zlib.pyd") returned NULL. Error: The specified module could not be found (126).
Now if I change 'bundle_files': 3, I have myApp.exe running just fine, though I get a cluttered distribution directory. Any ideas about what is going wrong here?
I've looked everywhere. Stackoverflow, various messageboards, the py2exe website, the pyinstaller website...nothing is helping. Including the selenium module, particularly making an exe that supports firefox, seems impossible. I am starting to pull out my hair because using either py2exe and pyinstaller is becoming a huge headache.
Both py2exe and pyinstaller have their share of problems.
My goal is to make one single exe file, without any extra directories, so that other people can use my program if they do not have python/modules.
With py2exe, if I create a setup.py file as such
from distutils.core import setup
import py2exe
setup(
name='Ask Alfred',
data_files = [('Drivers', ['Drivers/chromedriver.exe',
'Drivers/webdriver.xpi','Drivers/webdriver_prefs.json'])],
version='1.0',
description='Find emails fast!',
author='Me',
windows=[{'script': 'alphy.py'}],
options={
'py2exe':
{
'skip_archive': False,
'optimize': 2,
}
}
)
it will create an exe in the dist folder and a Drivers folder with the files I need, however, if I try to run the exe it will tell me that it could not find these files (because it is looking for them in the library.zip folder). On top of that, my GUI looks terrible (fonts are now grey instead of black and images with white backgrounds now have grey backgrounds).
With pyinstaller, if I use the "--onefile" flag when creating the exe it does not work at all/neither firefox nor chrome gets started.
With either, I only get workable results if I choose to not archive/not make one file. In that case, pyinstaller delivers a fully working solution.
Try this:
options={
'py2exe':
{
'skip_archive': True,
'unbuffered': True,
'bundle_files': 2, #assuming you dont want to include the python interpreter
'optimize': 2,
},
},
zipfile = None
I have a Python 2.7.2 program with wxPython 2.8.12 and comtypes 0.6.2 dependencies on a win XP SP3 machine. I am using py2exe to produce windows distributables with the following setup:
setup(
options = {
"py2exe": {
"packages": ['wx.lib.pubsub']
}
},
windows = [
{
"script" : "entry.py",
}
],
data_files=[("bitmaps", ["../resources/icons/app_big.png",
"../resources/icons/app_medium.png",
"../resources/icons/app_small.png",
"../resources/icons/app_small_new.png",
"../resources/icons/app_small_bad.png",
"../resources/icons/cross_hover.png",
"../resources/icons/cross.png",
"../resources/icons/delete.png",
"../resources/icons/refresh.png",])]
)
I am also using the IEHtmlWindow control.
What is happening is that whenever I issue the command at the Python console, py2exe runs for a second with the following output:
running py2exe
* searching for required modules *
and then appears to hang indefinitely until I press Ctr+z.
I have tracked down the problem to the import :
from wx.lib.iewin import IEHtmlWindow
which seems to be causing the problem.
Any suggestions?
Solved, the problem was that comtypes generated a very large module file which was taking too much time to parse by py2exe:
comtypes.gen._3050F1C5_98B5_11CF_BB82_00AA00BDCE0B_0_4_0
The workaround is to patch py2exe source code (ver 0.6.9) as pointed out by Erez Bibi in his post:
http://groups.google.com/group/wxPython-users/browse_thread/thread/52deb8a0bc1cdc5e
and now with the setup file
options={
"py2exe": {
'packages': ['wx.lib.pubsub'],
'includes': ['comtypes.gen._3050F1C5_98B5_11CF_BB82_00AA00BDCE0B_0_4_0'],
'skip_scan': ['comtypes.gen._3050F1C5_98B5_11CF_BB82_00AA00BDCE0B_0_4_0']
}
},
everything seems to be working great once again.
There are actually two versions of IEHtmlWindow. You can try importing the other one:
from wx.lib.iewin_old import IEHtmlWindow
And see if that works. If it does, awesome. If not, then you should probably go cross-post to the py2exe mailing list and/or the wxPython mailing list.