PySimpleGUI to android or to exe - python

Im working in a simple idle game in python and its interface is made trought PySimplegui, then it came to me two questions:
How do i transform my python code into an executable file?
There is any way to make my code become an Android application? if yes, how?

There are many solutions available. You might want to look at py2exe.
I'm not sure if you can turn a python program into an android program. PySimpleGUI doesn't work with android.

There's a very simple solution to this. Use the PyInstaller module to convert your python script to an executable file. The best thing about PyInstaller is that it will fetch all your dependencies and stack all these to an executable file. You can follow this simple line of code from your script directory in your command prompt
pyinstaller --onefile -w [your_script_name.py]
You can also watch this video, this guy explains it pretty well : https://youtu.be/UZX5kH72Yx4
Also here's the PyInstaller manual: https://pyinstaller.readthedocs.io/en/stable/index.html
Now to convert into .apk file, to the best of my knowledge I don't think you can directly convert your python script to .apk. I would recommend using KIVY to build an android app by python.
I am sharing a tutorial here though I don't know how good this is, you can check for yourself: https://youtu.be/mUdnjNGePZw

Related

Creating an executable kivy app and exe installer

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.

Converting a entire python project to exe

So I've made a project which takes a photo of your face or you can use any image and let it be fed into a neural network trained to classify celebrities. With that, you can figure out what celeb you look like.
Here is the Video and GitHub link.
I wanted to convert it to exe so that it's easier for people to download and use it but so far I've tried cx_freeze, pyinstaller and none of them work. I can't use py2exe because I'm on python 3.5.
I was able to convert live_detect.py(which is the main python script that runs the program) to an exe with pyinstaller but when I run it I got the following error.
I think a lot of the python to exe converter would have trouble converting a project this size. Other than modules, there are a lot of different items needed in different directory for the neural network model and so on. Was wondering if any of you had any suggestion.
There is a program called auto-py-to-exe which creates an exe out of your program without requiring you to create a setup file. The interface is great and allows you to easily create and exe without creating a setup.py. This also allows you to package your app as a single exe, without any other files. Below is a screenshot:
You can install the program by typing into the command line:
python -m pip install auto-py-to-exe
You can run it by typing in:
auto-py-to-exe
To see more about auto-py-to-exe, please visit the PyPI page at https://pypi.org/project/auto-py-to-exe/.

What should I put in the folder of my program if I want to embed Python to a C++ program?

I wrote a program with Qt and I embedded a .py file in it to do some work.
On my computer which has the Python interpreter installed, the program can run correctly, but when I run it on my roommate's PC, which has NO Python interpreter installed, the program crashed.
The part which is written with Qt runs well but when I push a button to call .py to do some work, the program crashes.
I think the problem is that I haven't put the std library and some other key files of Python into the folder of my program, but I have no idea what files should I pack into it.
So if the problem is really what I thought, what should I do to solve it?
Namely, which files of Python should be packaged into a program to run on the PC with no Python interpreter ?
Thanks in advance.
------------update------------------
As for the code of Python, it's just a hello-world for test and learning. I copy the whole Python34 folder into the program and the question has been solved:). Though it may not be a right way, it works.
Python's documentation has a reference manual for the C/C++ API.
The file I believe you're referring to is Python.h, though I'm no expert on this. It's considerably easier to embed C than C++, and this gives some of the more simple examples. As far as I know, you shouldn't need to worry about the interpreter for compiling to an executable.

Create a desktop icon for a Tkinter script

I have written a python script with a Tkinter GUI. I would like to create a desktop icon that will execute this script so that the end-user (not myself) will be able to double-click the icon and have the GUI load, rather than 'run' the script from the terminal or python shell and then have to F5 from there.
Is there a way to do this? I have googled many arrangements of my question but most answers seem to be normal python scripts, not ones which are Tkinter based.
I am using a Raspberry Pi with Wheezy and Python 2.7
Thanks in advance.
I create executables(icons that I click to start the programs I write) using 'py2exe'. I use windows 7 and I am not sure if it would work for you with Raspberry Pi, but a google search may clear that up for you. I will provide the link below. Basically you end up with a folder with the executable(icon) and also some files, without which the executable won't work. It's unfortunate that you get this extra 'baggage', but it's still handy and the best solution I have come across. I don't think there is a much better way, but I am not 100% on that. Interestingly, I found that you could delete most of these baggage files and the executable would still work, it was trial and error, but it didn't take long. If I want to send the folder to someone, I zip it first.
py2exe is here
If you need a 64 bit binary you can get it here, along with, actually, pretty much every other version. get py2exe here also
Besides creating executable file other option is create simple .bat file:
Open notepad
Enter "C:\ProgramData\Anaconda3\python.exe" "C:\Users\Your ID\script.py"
First part is path to python.exe, second to your python script
save file as .bat file, ex. "open_program.bat"
Now simply double click on saved .bat file icon should open your script.
I like using cx-freeze to convert python scripts to exe.
There is very easy to follow documentation to do this. In short, you create a setup.py script that specifies what libraries and packages you want to include or exclude in your application.
You can then run the build in the console and it will create a build folder, in which will be an Application File. You can create a Desktop short cut using send to and selecting desktop.
Documentation link
You can save the script as a .pyw file so the user can click on the file and the GUi would open

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