Trying to use Py2exe, keep getting errors - python

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.

Related

Python exe file fails due to ModuleNotFoundError: Numpy. This is confusing because numpy is already installed and the program works in Pycharm

I've written a Python program using pandas in Pycharm which works really well. However when I try to convert the Python program into an .exe file using pyinstaller in command prompt, the program fails. It successfully converts to an exe file but wehen I execute the program, a new window appears for 0.25 seconds and than terminates. I took a print screen of the window and the error it says is
"ModuleNotFoundError: No module named numpy. "
This is really confusing as Numpy is installed and the program executes perfectly in pycharm. I've tried copying and pasting the code to a new file, and created a new python file with that code. Still getting the same issue. I'd appreciate any advice you can provide :)

Python: no module named 'bottle-websocket' when running an executable made with PyInstaller, including Eel module

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.

py2exe - single file exe-tkinter program not executing

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().

Error converting GUI to standalone executable using Py2exe

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)

how make python program run hidden mode in .exe format?

I have a python program that run without console in app.pyw file format. I converted that program to .exe file using py2exe using this script
from distutils.core import setup
import py2exe
setup(console=['app.pyw'])
now the app.exe application working fine,but app will not work without console window. I want to run my app without console window in .exe format
(I cant add a comment )
I suggest that you read the module 'distutils.core' where setup is defined.
The para 'console=['app.pyw']' might be your problem.
Here you don't need to add .pyw just edit your py2exe setup script
replace console=
by windows=
should be something like that:
from distutils.core import setup
import py2exe
setup(windows=["app.pyw"])
try setup(windows=["name"]) instead of console. When theres no GUI window to run maybe itl hide it..

Categories

Resources