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.
Related
I am currently trying to use cx_Freeze to create a .exe file for my python scripts.
First, do cx_freeze get all data on the folder into the build folder?
Secondly, I'm having an issue when launching the .exe file. The fact that the first file opens the second one could be the issue ?
The console opened and closed, according to another post on Stackoverflow, I created a .bat file containing :
myfilename.exe%1
pause
to check out what the issue is and I got this issue :
Issue
I've really no idea what to do next since I tried many things on the setup.py to make things working.
Here is the setup.py :
"""setup.py"""
from cx_Freeze import setup, Executable
import os
os.environ['TCL_LIBRARY'] = "C:\\Users\\Roukira\\AppData\\Local\\Programs\\Python\\Python36\\tcl\\tcl8.6"
os.environ['TK_LIBRARY'] = "C:\\Users\\Roukira\\AppData\\Local\\Programs\\Python\\Python36\\tcl\\tk8.6"
build_exe_options = {"includes": ["tkinter"]}
setup(name="todolist",
version="0.1",
description = "A simple to do list with differnt tabs per account.",
options = {"build_exe": build_exe_options},
executables = [Executable("login_system.py",base=None)])
I'm only using pillow as an external module but it doesn't seem to be the issue.
Thanks for your help by advance !
EDIT : I managed to fix it by adding the ddl missing files path inside the "include_files" option:
build_exe_options = {"packages": ["os", "tkinter"], "include_files": ["to_do_list.py","336sur525.gif","384sur540.gif",
"accounts.txt","button_hide_2.gif","button_quit_2.gif","choose.gif","icone.ico","user.gif",
r"C:\Users\Roukira\AppData\Local\Programs\Python\Python36\DLLs\tcl86t.dll",
r"C:\Users\Roukira\AppData\Local\Programs\Python\Python36\DLLs\tk86t.dll"]}
My script was using a subprocess.call function to call another script, so it didn't work after becoming .exe, I added the .py file inside the "include_files" and it worked as intended.
I'm trying to create an exe using the following config options -
setup(name='tidalZabbix',
version=version,
description='python module to submit job stats to Zabbix',
url='',
author='Me',
author_email='me#company.com',
license='',
# folders with functions
console=[{'script': os.path.join(BASE_DIR, 'code/tidal_zabbix.py')}],
options={
'build': {'build_base': 'c:/tidalZabbix/build'},
'py2exe':
{
'dist_dir': 'c:/tidalZabbix',
'includes': ['decimal'],
}
}
)
I have a separate module in the code directory called code/ZabbixSender.py
when I try to run python setup.py py2exe I get the following error -
The following modules appear to be missing
['ZabbixSender']
If I move the ZabbixSender.py to the same location as my setup.py the build works fine.
ie. if I do this:
'includes': ['decimal', 'code.ZabbixSender'],
or
'includes': ['decimal', 'ZabbixSender'],
It still doesn't find the Module.
I'd like to think this is bad error reporting by p2exe.
The solution has nothing to do with my py2exe config but in the tidal_zabbix.py script being called.
This was the "incorrect" import
from ZabbixSender import ZabbixPacket, ZabbixSender
As soon as I modified it to this -
from code.ZabbixSender import ZabbixPacket, ZabbixSender
The build worked with no issues. Odd though considering running directly from python had no issues with the code.
So I'm trying to put together an auto-update functionality for my standalone OSX Python application, that's built on PyObjC. It works great simply packaging it via py2app, but I'm attemping to freeze it with Esky as part of an effort to implement the update feature.
As far as I can tell it's my setup.py formatting for Esky. I'm not sure exactly how to tell Esky to pass on the name of my .Xib file to py2app. Here's what my direct py2app setup.py looks like, successfully including the required .Xib file for the GUI:
setup.py for Py2app
from setuptools import setup
APP = ['MyApp.py']
DATA_FILES = ['MyApp.xib']
OPTIONS = {'argv_emulation': False, 'packages' : ['PIL']}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
iconfile="MyApp.icns"
)
Looking around at other people's posts, it looks like you can pass settings to py2app via the slightly differently structured Esky setup.py, but I can't for the life of me figure out the exact structure of the arguments to pass the .Xib file to py2app, from Esky.
setup.py for Esky
from esky import bdist_esky
from distutils.core import setup
setup(name="MyApp",
version="1.3.3",
iconfile="MyApp.icns",
data_files=['MyApp.xib'],
scripts=["MyApp.py","midheaven.py"],
options={"bdist_esky":{
"includes":["PIL"],
"excludes":['pydoc'],
"freezer_module": "py2app",
"freezer_options": {
"plist": {
'argv_emulation': False,
'packages': ['PIL'],
},
"data_files": ['MyApp.xib'],
},
},
},
)
Everything packages without an error, but of course if I try to run the Esky freeze of the app it crashes right away. I'm positive it's because it's not attaching the .Xib GUI properly. Anyone have experience with this, or ideas on how this should actually be formatted? Would absolutely love to figure this out and have it up on here for posterity.
You are correct esky does something different than what you might expect. Looking in the demo/tutorial folder is what got me on the right path.
setup(name="MyApp",
data_files=[('', ['MyApp.xib']),
('files', ['file1', 'file2']),
('img', glob(r'.\img\*.*'))
]
...
So you have a whole bunch of tuples, where the first entry is the path in your package to include the files and the second is an iterable of files to put there
You can remove the second instance of data_files that you have in the options dict.
Update
Try
from esky.bdist_esky import Executable
executables = [Executable('example_gui.py', icon='myico.ico', gui_only=True,)]
setup(
scripts = executables
...
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
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.