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.
Related
I'm trying to make with Python an EXE/MSI of my script, but in my script I use the library tkinter.tix i use that to create a Balloon tooltip. If i execute the script with the IDLE runs very well, but if i try to make an EXE(auto-py-to-exe) or MSI(cx_Freeze), shows me an error.
I import the module like this:
from tkinter.tix import *
I attach the error in picture.
I appreciate you can help me!!! Thanks...
You need to copy the tix folder in the Python installed folder into the distributed folder as well.
Below is a sample setup.py when cx_Freeze is used:
from cx_Freeze import setup, Executable
# change to the correct path for the tix folder in your system
include_files = [(r'C:\Python38\tcl\tix8.4.3', r'lib\tkinter\tix8.4.3')]
build_exe_options = {
'include_files': include_files,
}
bdist_msi_options = {}
setup(
name='Demo',
version='0.1',
options = {
'build_exe': build_exe_options,
'bdist_msi': bdist_msi_options,
},
executables=[Executable('tix-demo.py', base='Win32GUI')],
)
Then build the MSI by executing the following command:
python3 setup.py bdist_msi
I'm creating an app on my Mac (Catalina 10.15.4, system python 3.7) using py2app with python 3.7 and the IDLE IDE. The app is called network_plotter.py and calls functions in another file, network_tools.py. Currently both files reside in the same directory,
Including the line import network_tools at the start of network_plotter.py allows me to run the file network_plotter.py in IDLE with no problems.
Now to create the network_plotter app Following the py2app documentation instructions, I created my setup file, which looks like the following:
from setuptools import setup
APP = ['network_plotter.py']
DATA_FILES = []
OPTIONS = {}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
I need for the network_tools.py script to be included in the final app distribution, and I'm not sure what to modify above to do so. I've tried inserting after app=APP, each of the following lines, none of which works:
py_modules=['/Users/fishbacp/Desktop/network_tools']
ext_modules=['/Users/fishbacp/Desktop/network_tools.py']
scripts=['/Users/fishbacp/Desktop/network_tools.py']
In each case, the final app will not run, either when I double-click on it or try running it from the terminal. The latter approach leads to the error message, "No module named 'pygments.lexers.python"
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've created a program that pulls information from routers using SNMP (via PySNMP module). The application works great and I now what to compile it into a standalone application so that I can distribute it to my co-workers. However, after trying both Py2exe and PyInstaller, I've been unsuccessful in compiling a working application. I have searched the internet (a lot!) trying to find an example of someone who has successfully been able to compile their PySNMP application, but haven't been able to find anyway. Is there a better way to compile this or am I just doing it wrong?
These are the modules I've imported:
from Tkinter import *
import tkMessageBox
from pysnmp.entity.rfc3413.oneliner import cmdgen
This is the setup.py I've created for Py2exe:
from distutils.core import setup
import py2exe
setup( console = [
{ "script": "RSSIChecker.py",
}],
options = {
"py2exe":{
'includes': [
'pysnmp.smi.mibs.*',
'pysnmp.smi.mibs.instances.*'
]
}
}
)
Any suggestions?
With the following setup.py, a pysnmp-based app can be packaged with py2exe right out of the box (see line 101 and below). There are also some additional modules added implicitly into py2exe packaging as they are used by the app, not pysnmp itself.
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.