packing selenium with py2exe - python

I'm trying to pack selenium with py2exe howerever despite following the instructions here Python - Trouble in building executable
with the setup.py being:
from distutils.core import setup
import py2exe
setup(
console=['PlanOfCareModified9GUI.pyw'],
options={
"py2exe":{
"skip_archive": True,
"unbuffered": True,
"optimize": 2
}
}
)
copying and pasting the webdriver_prefs.jsonand webdriver.xpi into the dist directory as instructed by the link above. it still spits out this:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Python34\\dist\\lib
rary.zip\\selenium\\webdriver\\firefox\\webdriver_prefs.json'
I have been searching all over the internet for about 2 days now and still found nothing. The closest I came to a solution was on the link above. but none of the answers fixes this issue.
I am on Python 3.4
and am using selenium 2.45.0
I've even tried putting the webdriver_prefs.jsonand webdriver.xpi inside library.zip but when the app is ran the error is still there.
how do we solve this

Related

Packaging Selenium in py2exe

I am building a simple python app (myFile.py), using Python 3.4 with Selenium v2.44 (firefox web driver) and PyQt4 and want to distribute it. However, I am running into some problems including the webdriver.xpi and webdriver_prefs.json into the library.zip in my dist file.
Searching has given me plenty of results of people with the same problem, however, none of the proposed solutions seem to work for me.
My current setup.py:
from distutils.core import setup
import py2exe
wd_path = 'C:\\Python34\\Lib\\site-packages\\selenium\\webdriver'
required_data_files = [('selenium/webdriver/firefox',
['%s\\firefox\\webdriver.xpi'%wd_path, '%s\\firefox\\webdriver_prefs.json'%wd_path])]
setup(
windows= {"myFile.py"},
data_files = required_data_files,
options = {
"py2exe":{
"skip_archive": True,
"unbuffered": True,
"includes":["sip", "PyQt4"],
'optimize': 2
}
},
requires=['selenium'],
)
However, when the dist is created, I still have a library.zip that I can't manually add webdriver.xpi and webdriver_prefs.json too, additionally, it just creates a directory called selenium in the dist folder, it does not add it to the library. I was under the impression the -skip_archive option would NOT create a .zip file, but one is being created regardless.
Thanks in advance for your help,
Ryan

Cannot Include gi.repository.Gtk in py2exe

I have a project in Python 3.4 and GTK+ 3. I'm on Windows XP SP3 32-bit (VirtualBox).
I need to compile down to an executable using py2exe. (Do NOT suggest cx_freeze. It has ten times the problems on this project than py2exe).
My setup.py is as follows.
#!/usr/bin/python
from setuptools import setup
import py2exe
setup(name="Redstring",
version="2.0",
description="REDundant STRING generator",
author="MousePaw Labs",
url="http://www.mousepawgames.com/",
maintainer_email="info#mousepawgames.com",
data_files=[("", ["redstring.png", "redstring_interface.glade"])],
py_modules=["redstring"],
windows=[{'script':'redstring.py'}],
options={"py2exe":{
"unbuffered": True,
"compressed":True,
"bundle_files": 1,
'packages':['gi.repository'],
}},
zipfile=None
)
When I run it via C:\Documents and Settings\Jason\Desktop\redstring2>python setup.py py2exe, I get the following output (in full).
running py2exe
running build_py
1 missing Modules
------------------
? gi.repository.Gtk imported from __SCRIPT__
Building 'dist\redstring.exe'.
C:\Documents and Settings\Jason\Desktop\redstring2>
The actual script, redstring.py, runs without a hitch in my Windows environment. In that, I have the following (working) line of code: from gi.repository import Gtk That is ALL I import from gi.repository in the entire project.
If I swap the line in setup.py to 'packages':['gi'],, the error output switches to about 24-some-odd missing modules, all of them belonging to gi.repository. If I try and import "Gtk" or "gi.repository.Gtk" in either 'packages': or 'includes':, I get an error that the file in question being imported cannot be found.
I spent eight hours on #python (IRC channel) today, and no one could solve this. I need this packaged down to a Windows binary this week.
NOTE: This question is not a duplicate; while it is a similar issue, it is a) not the same error message, and b) neither answer solves the question in any way.
I solved this by, first of all, downgrading to Python 2.7. (GTK+ 3.8 is still fine.) py2exe apparently has known issues with Python 3.
Second, I switched...
options={"py2exe": {
"bundle_files": 1,
}
to
options={"py2exe": {
"bundle_files": 3,
}
For some reason, py2exe cannot include certain files needed to run the gi library when 'bundle_files' is set to 1 or 2.
The full setup.py that works with py2exe for my project can be found on GitHub. I run it on cmd with python setup.py py2exe.

15 Python scripts into one executable?

Ive been tinkering around all day with solutions from here and here:
How would I combine multiple .py files into one .exe with Py2Exe
Packaging multiple scripts in PyInstaller
but Its not quite working the way I thought it might.
I have a program that Ive been working on for the last 6 months and I just sourced out one of its features to another developer who did his work in Python.
What I would like to do is use his scripts without making the user have to download and install python.
The problem as I see it is that 1 python script calls the other 14 python scripts for various tasks.
So what I'm asking is whats the best way to go about this?
Is it possible to package 15 scripts and all their dependencies into 1 exe that I can call normally? or is there another way that I can package the initial script into an exe and that exe can call the .py scripts normally? or should I just say f' it and include a python installer with my setup file?
This is for Python 2.7.6 btw
And this is how the initial script calls the other scripts.
import printSub as ps
import arrayWorker as aw
import arrayBuilder as ab
import rootWorker as rw
import validateData as vd
etc...
If this was you trying to incorporate these scripts, how would you go about it?
Thanks
You can really use py2exe, it behaves the way you want.
See answer to the mentioned question:
How would I combine multiple .py files into one .exe with Py2Exe
Usually, py2exe bundles your main script to exe file and all your dependent scripts (it parses your imports and finds all nescessary python files) to library zip file (pyc files only). Also it collects dependent DLL libraries and copies them to distribution directory so you can distribute whole directory and user can run exe file from this directory. The benefit is that you can have a large number of scripts - smaller exe files - to use one large library zip file and DLLs.
Alternatively, you can configure py2exe to bundle all your scripts and requirements to 1 standalone exe file. Exe file consists of main script, dependent python files and all DLLs. I am using these options in setup.py to accomplish this:
setup(
...
options = {
'py2exe' : {
'compressed': 2,
'optimize': 2,
'bundle_files': 1,
'excludes': excludes}
},
zipfile=None,
console = ["your_main_script.py"],
...
)
Working code:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {
'py2exe' : {
'compressed': 1,
'optimize': 2,
'bundle_files': 3, #Options 1 & 2 do not work on a 64bit system
'dist_dir': 'dist', # Put .exe in dist/
'xref': False,
'skip_archive': False,
'ascii': False,
}
},
zipfile=None,
console = ['thisProject.py'],
)
Following setup.py (in the source dir):
from distutils.core import setup
import py2exe
setup(console = ['multiple.py'])
And then running as:
python setup.py py2exe
works fine for me. I didn't have to give any other options to make it work with multiple scripts.

Make exe file from python selenium tests

I try to build my python selenium tests in exe file and run it on many machines for keeping tests independent of the environment. But result *.exe file can't find selenium webdriver. How can I include all selenium dependencies in *.exe file? Or maybe is there some another way for it?
Is it possible to make virtual environment and distribute it?
I am assuming you are using py2exe for generating exe. You will need to specify the location of selenium webdriver in the 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', ['D:/Python27/Lib/site-packages/selenium/webdriver/firefox/webdriver.xpi'])]
setup(
name='General name of app',
version='1.0',
description='General description of app',
author='author name',
author_email='author email',
url='',
windows=[{'script': 'abc.py'}], # the main py file
data_files=data_files,
options={
'py2exe':
{
'skip_archive': True,
'optimize': 2,
}
}
)
Like most other binary, it's probably required to include the DLL or whatever library you need, with the binary file. For example:
C:\tests\
run_tests.exe -- this will read from webdriver.dll
selenium-webdriver.dll
Also, from my .NET days i know that you were able to actually embed the library straight into the EXE, which makes it rather large.
You may try pyinstaller,it is simple to install and simple to use.
Install:
pip install pyinstaller
To exe:
pyinstaller yourprogram.py
This is old but I was looking for the same thing and I did have to dig in many different websites to find out my problem, so hopefully this will help others.
I was using py2exe to build my exe file but it didn't work so I decided trying pyinstaller and yeah, it worked.
Just gonna put the things in items to be more organized:
Py2exe:
I first started with py2exe and I was getting error like this:
python setup.py py2exe Invalid Syntax (asyncsupport.py, line 22)
I could fix it by deleting some of the things in the setup file, it looked like this in the end.
data_files = [('selenium/webdriver/chrome', ['C:\Python27\Lib\site-packages\selenium\webdriver\chrome\webdriver.py'])]
setup(
name='General name of app',
version='1.0',
description='General description of app',
author='author name',
author_email='author email',
url='',
windows=[{'script': 'final_headless.py'}], # the main py file
data_files=data_files,
options={
'py2exe':
{
'skip_archive': True,
'optimize': 2,
'excludes': 'jinja2.asyncsupport',
'dll_excludes': ["MSVCP90.dll","HID.DLL", "w9xpopen.exe"]
}
}
)
It could run the py2exe but the exe file didn't work, then I moved to pyinstaller.
Pyinstaller:
For me pyinstaller look way easier than py2exe, so I am keeping with this from now. We only "problem" was that without the webdriver in the path the exe doesn't run.
But as soon as you have it in your variables path you are good to go.
Conclusion, using pyinstaller was my solution + adding webdriver to path.

cx_freeze + PyQt5 + python

I'm running in circles with a really strange thing happen. Basically I'm trying a simple window app with PyQt5+python3.3+cx_freeze4.3.2. The problem runs perfect calling the python:
python test.py
Now the second part the basic setup.py to the cx_freeze:
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
options = {
'build_exe': {
'includes': 'atexit'
}
}
executables = [
Executable('test.py', base=base)
]
setup(name='test',
version='0.1',
description='test',
options=options,
executables=executables
)
build it:
python test.py build
The follow folder is created:
build/exe.win32-3.3:
/platforms
/imageformats
test.exe
icudt49.dll
icuin49.dll
icuuc49.dll
libGLESv2.dll
library.zip
PyQt5.QtCore.pyd
PyQt5.QtGui.pyd
PyQt5.QtWidgets.pyd
python33.dll
Qt5Core.dll
Qt5Gui.dll
Qt5Widgets.dll
sip.pyd
unicodedata.pyd
_bz2.pyd
Now running test.exe everything works fine as it should.
The problem comes when I copy the build folder to other PC. An error pops-up when I run the test.exe
This application failed to start because it could not find or load the
QT platform plugin "windows".
Available platform plugin are: minimal, offscreen, windows.
Reinstalling the application may fix this problem
According everything I read it's about dlls on plataforms/ the .exe don't find qwindow.dll inside. Why it's only happen in other PC (win7)?? The developement PC (win7) works fine. To debug it and to have sure that qwindow.dll used is the one inside on plataforms/ I rename the folder to plataformFOO/ and try run the test.exe and now same problem in dev PC, so, the dll is in correct folder, rename it back to plataforms/ and everything working fine. Why the hell is not working in others PCs if the OS is the same and the folder is a simple copy of the one on dev PC.
I google, read loads of stuffs but can't figure out the problem. If someone can help ;)
I had the same problem and I'm running Anaconda 4.4.0 Python 2.7.13 using PyQt5 and cx_Freeze 5.0.1
Copy anaconda/library/plugin/platforms directory into the directory containing the .exe.
Run the executable and it should work

Categories