Creating an executable kivy app and exe installer - python

I created a data-miner GUI for twitter with kivy and am currently having a lot of trouble turning it into an exe. I tried following this video and import glew and sdl2 into my spec but after doing pyinstaller main.spec, my executable still would not open.
Is it because I have more than one files and folders for my program (here is the link to the github repo for my project), if so, how do you deal with that?
In addition, if I manage to success create a working exe, how do I create an exe installer that other people can use to install the executable?

Making an executable from a complex script like yours may become quite frustrating because of its dependencies. But I'm giving you a brief guide about what you need to follow to achieve your goal.
Create your main.spec file with console-mode enabled to see the exact error message for the app. (make sure to remove --noconsole from PyInstaller command or set console=True in spec file). Also use --no-upx in the build command to remove compression from output file (this helps with omitting some DLLs which may cause issues).
You need to make sure that every external module you used can pack correctly. I don't think you get any problem with either Kivy or Tweepy. But if you get any missing import error, try to check the solution for each one by searching the pattern [module] pyinstaller.
Your app has external resources like images, files, etc., which must be added to the packed executable and load properly. I wrote an answer about this here.
If you want a standalone executable, you need to use -F with PyInstaller command, which is more robust than using an installer to gather files in one directory mode.

Related

I have problem with Pyinstaller in python

I have a question if I use Pyinstaller to convert python file to exe will convert the modules with or not? , because i have python file with a lot of modules and i want to convert it how i can do it and avoiding this issue,
Thank u.
import requests
error:
ImportError: No module named requests
.
After discussion in comments basically the error is occurring when you try to open the generated file in another computer, however your aren't using any virtual environment so you can install the requirements and try to rebuild again but rather you want a stanalone exe file.
For that use :
pyinstaller --onefile your-script.py
# or pyinstaller -F your-script.py
## this should generate a stand alone executable file located in the dist folder.
About your concerns on how pyinstaller works
Does pyinstaller make copies of modules when building ?
The answer is simply : yes , as mentioned in the docs here PyInstaller reads a Python script written by you. It analyzes your code to discover every other module and library your script needs in order to execute. Then it collects copies of all those files – including the active Python interpreter! – and puts them with your script in a single folder, or optionally in a single executable file.
However, the variations of Python and third-party libraries are endless and unpredictable, if something goes wrong you can learn how to fix those issues by reading this page on the docs here
What to generate ?
you can read more here
Create a one-folder bundle containing an executable (default), -D, --onedir
Create a one-file bundled executable. you need to use -F ore --onefile
Finally
I highly encourage you to use separate virtual environment for each project.

Converting .py to .exe with a GUI frontend

I'm trying to convert .py to .exe , but I'm not able to convert it with the help of py2exe in the command line.
I searched on the internet about a py2exe with a GUI frontend and I got the results as:
GUI2EXE (3/5) (The best one I found, but the .exe comes with lots of .dll files and the .exe file is buggy and doesn't work properly.)
H-two-O (2/5) (Waste of time. Doesn't compile any .exe files associated with Tkinter. Very creative and useful for other file formats.)
PytoEXE (1.3/5) (Just as H-two-O , but doesn't compile Tkinter files to .exe)
GP2EXE (?/5) (I didn't try it out. Maybe you can give a view on it.)
PyBuilder (2.7/5) (Reliable, good GUI interface with options but lacks some of the features and compiling speed to that of GUI2EXE.)
PythontoEXE (1.3/5) (Same as PytoEXE)
But these weren't good. I need a compiler better than all of the compilers listed above which can compile Tkinter files to .exe without any bugs.
Here's how I use py2exe. I know this isn't what you're asking for, but according to my experience, it's really annoying until it works. So please hear me out.
Assuming your Python file is called main.py.
New file setup.py (same folder):
from distutils.core import setup
import py2exe
setup(console=['main.py'])
From here, you can create a .bat file in the same folder, or run it from the command line. Either way, you'll be running python setup.py py2exe to compile the code.

can you manualy make standalone python executeable? [duplicate]

This question already has answers here:
Create a single executable from a Python project [closed]
(3 answers)
Closed 3 years ago.
I wrote a script that will help a Windows user in her daily life. I want to simply send her the .exe and not ask her to install python, dlls or have to deal with any additional files.
I've read plenty of the stackoverflow entries regarding compiling Python scripts into executable files. I am a bit confused as there are many options but some seem dated (no updates since 2008) and none were simple enough for me not to be asking this right now after a few hours spent on this.
I'm hoping there's a better, up-to-date way to do this.
I looked into:
pylunch
py2exe
cx_Freeze
py2app (only for Mac)
pyinstaller
bbfreeze
but either I couldn't get them to work or couldn't understand how to get the result I need. The closest I got was with py2exe but it still gave me the MSVCR71.dll
I would appreciate a step-by-step answer as I was also unable to follow some of the tweaking answers here that require some prior understanding of how to use py2exe or some of the other tools.
I'm using Python 2.5 as one of the modules is only available for that version.
PyInstaller will create a single-file executable if you use the --onefile option (though what it actually does is extracts then runs itself).
There's a simple PyInstaller tutorial here. If you have any questions about using it, please post them...
Using py2exe, include this in your setup.py:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1}},
windows = [{'script': "YourScript.py"}],
zipfile = None,
)
then you can run it through command prompt / Idle, both works for me. Hope it helps
i would recommend going to http://sourceforge.net/projects/py2exe/files/latest/download?source=files to download py2exe. Then make a python file named setup.py.
Inside it, type
from distutils.core import setup
import py2exe
setup(console=['nameoffile.py'])
Save in your user folder
Also save the file you want converted in that same folder
Run window's command prompt
type in setup.py install py2exe
It should print many lines of code...
Next, open the dist folder.
Run the exe file.
If there are needed files for the program to work, move them to the folder
Copy/Send the dist folder to person.
Optional: Change the name of the dist folder
Hope it works!:)
I would join #Nicholas in recommending PyInstaller (with the --onefile flag), but be warned: do not use the "latest release", PyInstaller 1.3 -- it's years old. Use the "pre-release" 1.4, download it here -- or even better the code from the svn repo -- install SVN and run svn co http://svn.pyinstaller.org/trunk pyinstaller.
As #Nicholas implies, dynamic libraries cannot be run from the same file as the rest of the executable -- but fortunately they can be packed together with all the rest in a "self-unpacking" executable that will unpack itself into some temporary directory as needed; PyInstaller does a good job at this (and at many other things -- py2exe is more popular, but pyinstaller in my opinion is preferable in all other respects).
1) Get py2exe from here, according to your Python version.
2) Make a file called "setup.py" in the same folder as the script you want to convert, having the following code:
from distutils.core import setup
import py2exe
setup(console=['myscript.py']) #change 'myscript' to your script
3) Go to command prompt, navigate to that folder, and type:
python setup.py py2exe
4) It will generate a "dist" folder in the same folder as the script. This folder contains the .exe file.
you may want to see if your app can run under IronPython. If so, you can compile it to an exe
http://www.codeplex.com/IronPython
You can create executable from python script using NSIS (Nullsoft scriptable install system). Follow the below steps to convert your python files to executable.
Download and install NSIS in your system.
Compress the folder in the .zip file that you want to export into the executable.
Start NSIS and select Installer based on ZIP file. Find and provide a path to your compressed file.
Provide your Installer Name and Default Folder path and click on Generate to generate your exe file.
Once its done you can click on Test to test executable or Close to complete the process.
The executable generated can be installed on the system and can be distributed to use this application without even worrying about installing the required python and its packages.
For a video tutorial follow: How to Convert any Python File to .EXE
You could create an installer for you EXE file by:
1. Press WinKey + R
2. Type "iexpress" (without quotes) into the run window
3. Complete the wizard for creating the installation program.
4. Distribute the completed EXE.

Distributing python application tutorials

Hi as a python newbie I have written a small python application that can convert an excel worksheet into a sqlite database table. Its not a terribly complex application but it does make use of external modules/package like xlrd (http://pypi.python.org/pypi/xlrd) which I had to download and install when writing my app.
Now that is all done I would like to distribute it amongst my friends, all windows users, while they have python on their machines, they may or may not have the xlrd modules.
I would like to package my app, make sure it includes everything that it needs to run, and share the final .zip file with my friends so they can use the application. Is there a good tutorial that covers how to package a python application, with all the necessary external modules/packages, so that another windows user, can easily run my application.
I keep hearing about disutils, can anyone point me to some good tutorials, or any other python packaging tutorials that show how to get everything into a simple easy to distribute file.
Many thanks
Note: I also want to include the sqlite database file with my application, so the end user doesn't have to worry about anything
First download Pyinstaller and save it somewhere. Then, if you're running Python 2.6 or 2.7 go and install pywin32.
Go create a directory for your output file.
Open Command prompt and enter the fallowing:
python path/to/pyinstaller/pyinstall.py file/to/be/converted.py --onefile
If you want to add an icon, add the --icon argument.
If you want it to hide the CMD window add the --windowed argument.
So if you wanted it to use an icon and hide the CMD window it would look like this:
python path/to/pyinstaller/pyinstall.py file/to/be/converted.py --onefile --icon="path/to/icon.ico" --windowed
The --onefile argument makes the saves everything into one file, without it, the output would be would be a lot of files.
The output is saved in the "dist" folder in the directory it was using.
After you convert the python script in to an .exe, put it in a .zip file along with any other files you need (in your case the squite database file) and you can give it to anyone without them needing to have Python at all.
If you want a program to do this all for you, you can download a program called PTEC.

Python 3 project into exe?

I've made my first Python program, using Python 3.2. Now I'm trying to figure out how to make it an executable.
I pretty much only need it for Windows only. I've searched as much as possible and found out that py2exe doesn't support Python 3. cxfreeze does, but I can't figure out how to make a single executable of my program with it. I need it as a portable one-file exe.
Please bear with me as I am a total newcomer :) Any help is appreciated.
You can use cxfreeze to make the executable (and other files it creates), compress them into a *.7z archive using 7-zip, then use 7-ZIP SFX Maker to turn it into a self extracting archive.
When creating the SFX archive, configure it so that the main executable cxfreeze generates runs when the files are extracted. You can also change the archives icon, as well as tell the archive to extract and run from a temporary folder.
When the user runs the exe, the files will extract to the temporary folder and the program will run. To the user, it will behave exactly like a normal exe file.
According to the Python docs, the only program that will package Python3 as an .exe in cx_freeze, and the cx_freeze developer has explicitly stated that he will not support single-file executables (due to the 'dirty hacks' needed, which some anti-malware programs flag as malware).
Comment on the feature request to add Python3 support to py2exe.
You can compare py2exe folder structure with new python3, and make similar. Then you could use SFX idea to store these folders like libraries, python script and interpreter and set script for SFX to just launch your application. As I remember, this is possible in WinRar, and as I think now, in other archivers.

Categories