I am new to python programming and development. After much self study through online tutorials I have been able to make a GUI with wxpython. This GUI interacts with a access database in my computer to load list of teams and employees into the comboboxes.
Now my first question is while converting the whole program into a windows exe file can I also include the .accdb file with it...as in I only need to send the exe file to the users and not the database..if yes how.
My second question is... I actually tried converting the program into exe using the py2exe (excluding the database...am not sure how to do that) and I got the .exe file of my program into the "Dist" folder. But when I double click it to run it a black screen (cmd) appears for less than a second and disappears. Please help me understand the above issue and resolve it.
am not sure if I have a option of attaching files...then I could have attached my wxpython program for reference.
Thanks in advance.
Regards,
Premanshu
The console could possibly appear if you used the 'console' parameter to setup(). Switch to 'windows' instead if that is the case. Can't say for sure without seeing your setup.py script. Possibly your app could also be opening console, but again hard to say without seeing source. One thing to check is to make sure you are not printing anything to stdout or stderr. You might want to redirect all of stdout and stderr to your log just in case, and do this right at the top of your start script so that if some 3rd party import was writing to stdout you'd be able to capture that.
The db is not part of your executable, so py2exe will not do anything with it. However, you should probably package your application with an installer, and you can make the installer include the db and install it along with the executable.
Related
Hello so I'm kind of new with programming and I buildt a program with python and kivy. The issue is that I am using auto-py-to-exe to convert the py files to exe but when I do it, it doesn't work well. The primary issue is that a windows command prompt opens when I run the app and if I close it, the app closes too. The other problem is that I can't share the file to someone else so that they can run it in another computer, and what happens is that the same command prompt kind of appears but then closes and the app doesn't open at all. I would appreciate it if someone could help me to understand how I can debug it as I don't even understand the problem in the first place.
I have been looking online for other people with the same issues but I haven't find any answer that applied to my case.
Try to choose Window Based(hide the console) and it wil works
If you choose “Console Based,” the console will open after running the executable file, which is recommended if your script generates console-based outputs. However, if you don’t want to show the console outputs when running the executable file, choose “Window Based”
I created a python code which creates a horse racing card betting game. I would like to share this game with my friends, who have macs, who do not have python or know anything about coding so they can play it. I have tried using pyinstaller to convert the file into a stand alone executable app. I used the command
pyinstaller --windowed Horse_Race.py
This works in that it creates a build and dist folder. The dist folder contains the app of the python code. When I run the app, however, it opens briefly (about 1s) then crashes without anything ever displaying on screen. The interesting part is that I can view the package contents of the app and run the code through my terminal by running the UNIX executable file which is within the package contents of the app.
In short the executable file works, however, the app will not run, and I cannot share the file with my friends who have macs because it just shows up as a text file. If anyone knows how to fix this issue or knows another creative way I can send my game to my friends please let me know.
Thanks for your help.
here is an easy souloution that saves time and does not require knowledge.
pip install auto-py-to-exe
and then just type
auto-py-to-exe
after typing the code above a window in your web browser will open with a ghraphical gui that looks like this
click here to go to image
I'm asking help today because I'm new to Tkinter and Pyinstaller (and python in general) and I'm having troubles with it.
I have a simple app working with sqlite, tkinter and pyinstaller to compile all of this in an executable program, the entrance point of my program is a file named main.py
This file calls all the dependancies (like the sqlite module for python, tkinter and my other files like classes etc...)
I made a very simple interface, with a Hello World in a tkinter label and a button to go to page 2 which displays page2 (also in a label), just to see if I'm capable of making it all run and compile all of these pieces together.
I can run it throught my shell executing it like : python main.py and everything is working fine.
But when I run pyinstaller on my linux machine, and start executing the program, nothing appears, my database.db (sqlite database file) is created but I don't have any interface like when I run it with my shell. The thing is getting even worse on windows where, once I've my .exe it just opens a shell and crash after few seconds, not even creating the database.
What I did is I created a 'log file', in which I write the steps of the program.
As you can see on the following picture, the 2 first prints are wrote in my log file (on linux), so I think it crashes when I try to create the window.
If any of you have an idea on what I do wrong, I would really appreciate help :)
General
From the PyInstaller manual:
Before you attempt to bundle to one file, make sure your app works correctly when bundled to one folder. It is is much easier to diagnose problems in one-folder mode.
As the comments suggested, use a catch-all try/except block to log all exceptions to a file. That is probably the best way to see what is really happening. Make sure that the logfile is created in an existing location where you have the necessary permissions.
I would suggest to take advantage of the built-in logging module instead of creating your own. It can e.g. automatically add from which file a log line was created.
IMHO, it is probable that the failures on Linux and ms-windows have completely different causes. You should probably treat them as different issues.
Linux
When you use single file mode, that file is unpacked into a temporary folder, probably somewhere in /tmp. Some Linux distributions mount the /tmp filesystem with the noexec flag. This is incompatible with PyInstaller.
ms-windows
On windows, there are basically two different Pythons; python.exe and pythonw.exe. Basically it is one of the quirks of windows that this is necessary. The latter is for GUI programs like tkinter programs. A tkinter script should not show a cmd window. So I'm guessing that PyInstaller calls your command with python.exe instead of pythonw.exe. From the manual:
By default the bootloader creates a command-line console (a terminal window in GNU/Linux and Mac OS, a command window in Windows). It gives this window to the Python interpreter for its standard input and output. Your script’s use of print and input() are directed here. Error messages from Python and default logging output also appear in the console window.
An option for Windows and Mac OS is to tell PyInstaller to not provide a console window. The bootloader starts Python with no target for standard output or input. Do this when your script has a graphical interface for user input and can properly report its own diagnostics.
As noted in the CPython tutorial Appendix, for Windows a file extention of .pyw suppresses the console window that normally appears. Likewise, a console window will not be provided when using a myscript.pyw script with PyInstaller.
Also, on windows it can matter which Python distribution you're using. I used to be a fan of Anaconda, but lately I've come to prefer the python.org version because it gives me less headaches. On anaconda Python I had the problem that tkinter programs would not launch without showing a cmd window, whatever I tried. Only switching to python.org Python solved that problem.
I create a single file python application with Pyinstaller using --onefile parameters.
Everything work as expected but the startup time is around 10 seconds on my machine. The problems is that during the file unpacking process of Pyinstaller package there are no visual feedback, so you don't know if the application is starting or even if you really clicked the icon. This problem became worse if the machine is slow (on my test with a very old machine i need almost 20 seconds to see the first login of my application)
There is a way to create some splash screen or visual feedback (like a progress bar as on unpackers) during the Pyinstaller bootstrap sequence?
Please note the question is about Pyinstaller unpacking process BEFORE the real application will be executed not by the application itself that already has is own splash screen
thank you
19.01.2018 - UPDATE1
My application is FULL GUI so i prefer to not use the console as "visual feedback" during the unpacking process.
There is a beta version of the splash screen!
So just use your normal pyinstaller command in cmd and add:
--splash splashfile.png
adding --splash splashfile.png gave me high pink color shades on splash screen, so I used JPG image with some colored background and it worked very well.
another update we need to close splash, within our project code in any suitable place feasible for us, else splash screen remains on top of UI until application itself is closed.
try:
import pyi_splash
pyi_splash.update_text('UI Loaded ...')
pyi_splash.close()
except:
pass
and put this splash screen close code with in try block as it is needed only for package execution,
and can just pass on exception and proceed at the time of development runs.
Update:
More elegant way to close the splash screen
if '_PYIBoot_SPLASH' in os.environ and importlib.util.find_spec("pyi_splash"):
import pyi_splash
pyi_splash.update_text('UI Loaded ...')
pyi_splash.close()
log.info('Splash screen closed.')
reason for discarding try/except because, if you generate console exe then try/except will unnecessarily generates warnings, so to completely avoid warnings also, this can be a good check..
I have been battling with this problem myself. Unfortunately, there is no feasible solution to the problem other than using the ugly console (completely agree there).
The problem stems from the fact that until PyInstaller unpacks all the files into a temp dir, no scripts will be run. From my research, there is no way to alter this functionality using currently available options within PyInstaller. It would be nice if the community behind PyInstaller would make this a standard feature of the module, but until then we may have to explore other installer options.
Happy programming!
One simple solution might be to display the console window after launching the application, which will output the status of the PyInstaller Bootloader while it is being opened.
To display the console, use the --console flag (or edit the .spec file to contain console = True) when bundling your application. These options are documented in the PyInstaller doc file.
There is a pull request got pyinstaller... Actually, it is already merged into master. It adds this functionality: https://github.com/pyinstaller/pyinstaller/pull/4887
At the moment you will need to build the pyinstaller to have this, but it is feasible. I managed to do this for my project without any deep knowledge in c/c++ etc.
I have no idea if this problem has the solution I want but here goes.
I'm making a PyQt4 program that apparently needs the console window to run properly. However, whenever I activate another window, sending the program I'm working on to the back, the only way I can get back to it is by closing all the windows in front of said window. I can't just click on the taskbar because the only thing that comes back is the console window.
I'm curious. Is there a way to have the GUI window activate along with, or independent of, the console window without having to go through the annoying process of closing (minimizing) potentially all the rest of your windows?
Edit: I just realized my question is pretty vague. Let me elaborate.
I'm compiling said program using pyinstaller.
The reason it needs the console window to work properly (I have tried using the .pyw file as well, to no avail) is because there's another program that's the core of this one that prints out to it in a way I can only describe as violently.
Apparently it won't be happy unless it has the console to record it's outbursts.
That being said, I need the console window. However, as I mentioned before, that is the only thing that comes up when the pyinstaller icon is clicked.
There is a gui attached to the console, but there's no way to get it back even after the user would minimize it because the pyinstaller icon insists it doesn't exist.
Maybe it has something to do with how I defined the window while programming it, but I don't see why that would be the case. Is there something in particular pyinstaller doesn't like that would make it act like this?
How are you launching the PyQt application?
If you're launching it with the python executable, it will create a console.
python my_application.py
Instead, launch it with the GUI version of python -- pythonw:
pythonw my_application.py
If the python path isn't in the system path, you may need to specify the whole path to the executable:
C:\python27\pythonw.exe C:\path\to\my_application.py