I am using py2exe to convert my program with multiple GUIs to a standalone executable. I used PyQt to create the GUIs. The main script I run instantiates the main UI, which contains buttons, tabs, etc. that can open sub-UIs. The main script is main_ui.py.
I followed the tutorial on how to use py2exe, so I have the following setup.py:
from distutils.core import setup
import py2exe
setup(windows=['main_ui.py'])
Then, in the CMD: > python setup.py py2exe.
I tried creating a practice exe with a simple script and everything worked. However, I got an error when I tried creating the exe from main_ui.py.
Here is the output:
L:\internal\(path)>python setup.py py2exe
running py2exe
creating L:\internal\(path)\build
creating L:\internal\(path)\build\bdist.win32
creating L:\internal\(path)\build\bdist.win32\winexe
creating L:\internal\(path)\build\bdist.win32\winexe\collect-2.7
creating L:\internal\(path)\build\bdist.win32\winexe\bundle-2.7
creating L:\internal\(path)\build\bdist.win32\winexe\temp
creating L:\internal\(path)\dist
*** searching for required modules ***
error: compiling 'C:\Python27\lib\site-packages\PyQt4\uic\port_v3\proxy_base.py' failed
SyntaxError: invalid syntax <proxy_base.py, line 26>
Here's proxy_base.py:
from PyQt4.uic.Compiler.proxy_metaclass import ProxyMetaclass
class ProxyBase(metaclass=ProxyMetaclass):
""" A base class for proxies using Python v3 syntax for setting the
meta-class.
"""
This came with PyQt4; does anyone know what's going on? Is this the right way to make my program into an executable?
I have encountered the same problem. There is very probably a better way, but removing the folder "PyQt4\uic\port_v3" solves the issue.
(see http://python.6.x6.nabble.com/PyQt-4-7-and-py2exe-error-td1922933.html)
Related
I was playing around with the eel module for Python - gives an opportunity to run HTML + CSS/JS with the python functionality.
Made a simple program, tried to make an executable out of it via PyInstaller.
No errors whatsoever, but when running this executable it crashes on the first line - import eel, telling - there is no module called 'bottle-websocket'.
I checked pip: eel, bottle-websocket are installed. Can't figure out what's the problem. Attachments:
main.py:
import eel
from os import path
eel.init(path.dirname(__file__) + "/web")
eel.start('main.html', block=False)
while True:
eel.sleep(10)
Error:
Picture with the error while I try to start the exe
EDIT:
PyInstaller Log
I was also having this same issue, but I finally fixed it, it was actually very very easy, first of all make sure you are using auto-py-to-exe to package your app.
After inserting necessary details (script file,, extra files etc), you would see an advanced options tab probably below, click on it to expand it, look for the hidden imports label and insert "bottle-websocket" in the input field representing the hidden imports, that's basically all you need to do
I HOPE THIS HELPS
Took me the whole day figuring out the solution, but finally, here it is:
Copy the plugin.py, server.py files from C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python36-32\lib\site-packages\bottle_websocket to C:\Users*YOUR_USERNAME*\AppData\Local\Programs\Python\Python36-32\Lib
Make sure you have this line as follows in your *.spec file generated by PyInstaller (FOR PYTHON 3.6 32bit):
datas=[('C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python36-32\lib\site-packages\eel\eel.js', 'eel'), ('PATH_TO_YOUR_WEB_FOLDER', 'YOUR_WEB_FOLDER_NAME')]
3)Run this command in cmd: python C:\Users\YOUR_USERNAME\AppData\Local\Programs\Python\Python36-32\lib\site-packages\eel\main.py HERE_SHOULD_BE_THE_PATH_TO_YOUR_WEB_FOLDER
this command will get the 'bottle-websocket' work and will make sure that it complies with the web folder and files.
I used below code to make execute of my program:
from distutils. core import *
import py2exe,sys,os
sys.argv.append('py2exe')
setup(options={'py2exe':{bundle_files':1,'compressed':True,'includes':["Tkinter",]}}'windows=['trial.py'],zipfile=None,)
It is creating single file .exe, but not executing.
same code with bundle_file 3 (without single file) is working fine.
trial.py:
import Tkinter
Tkinter.Tk()
mainloop()
Please help me to create a single .exe file for GUI program
PyInstaller is a much easier option that can be used from the console. Just pip install pyinstaller, enter your program's directory, and pyinstaller yourscript.py.
I am confused that you say trial.py is working fine when I get an error on my machine. mainloop() needs to be replaced by Tkinter.mainloop().
For example, lets say that the setup.py script is as follows
from distutils.core import setup
setup(
name='great_package_name',
version='1.0',
description='another great python package!',
packages=['greatness'],
scripts=['bin/some_script.py']
)
I want the bin/some_script.py to use the default program
/home/itzjustricky/anaconda2/envs/py33/bin/python
which is the python interpreter being used to call setup.py, i.e.
my-cpu: python setup.py
my-cpu: which python
/home/itzjustricky/anaconda2/envs/py33/bin/python
Is there a way so that setup.py automatically puts the
#!/home/itzjustricky/anaconda2/envs/py33/bin/python
header at the top of the bin/some_script.py file? Also it would be great if setup.py got rid of the .py file extension as well.
I could probably hack a way to use sys.executable to get the result, but is there a cleaner way? I am working in Python3. Thank you for any help in advance!
I just realized that simply by putting
#!/usr/bin/env python
at the head of the bin/some_script.py file solved my problem. I am not sure if anaconda is doing something behind the scenes. For getting rid of the extension, I just decided to name the some_script as bin/some_script from the start and that is good enough.
I have small program made in python with selenium, and now I'm trying to make an .exe with py2exe.. I get the exe but when I run it, terminal just pops up for split second then it terminates.
I tried to run .exe in cmd and It says that there is no such file as webdriver_prefs.json
Here is the setup.py I have:
from distutils.core import setup
import py2exe
setup(console=['file_name.py'])
Any input on how to resolve this is welcome.
Cheers.
Hi I am building a simple application that will have a combo box to select python scripts that are in a directory called scripts to create reports on a database. I was going to use py2exe to build the program so that the users don't have to have python and submoduals installed.
so how would i go about having the program run these scripts using the py2exe dist?
i thought about using system('command') and copying the python.exe from my install directory to just run system(os.curdir+'python.exe ' + script_to_run) the python.exe would then use the local copy of the python.dll and the libs that it needs to run which would just be reportlab and pyobdc
would that work or is there a better way?
(i also wouldn't mind building it in ironpython if that would be easier)
Micheal Foord has the following example for Embedding Ironpython from within Ironpython
The basic steps are to create your shell application. For a real lightweight GUI there is EasyWPF. Use pyc to compile your script to an exe and the standard library into a DLL. Depending on if you need to capture stdout from the scripts or pass variables in information into them, things can get more complicated as indicated in the article. A basic example is listed below.
import clr
clr.AddReference('IronPython')
clr.AddReference('System')
clr.AddReference('mscorlib')
clr.AddReference('Microsoft.Scripting')
clr.AddReference('MyStandardLib')
#Now you can reference things like 'import lxml as L .....
from IronPython.Hosting import Python
from Microsoft.Scripting import SourceCodeKind
spath = "C:/fred.py" # Path to script
engine = Python.CreateEngine()
#Now add your assemblies (like the standard library) to the engine
for assembly in clr.References:
runtime.LoadAssembly(assembly)
source = engine.CreateScriptSourceFromFile(spath, SourceCodeKind.Statements)
mod = engine.CreateScope()
runtime = engine.Runtime
source.Execute(mod)