Converting a entire python project to exe - python

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/.

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.

PySimpleGUI to android or to exe

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

Problem with path Dependency in Pyinstaller

I am currently working on "ubuntu 20.04". I have a classifier.py python file. My python file consists of machine learning packages like pandas, Sk learn etc. I have converted the python file (.py) into an executable file (.exe) using "Pyinstaller".
The generated .exe file works perfectly on my PC but when I try on another PC, it is depending on a path from my PC which is not present on the other PC, resulting in not working. The path is like Users/anaconda/lib etc.
Please help me, how can I solve the issue and also provide me with a good alternative like "Pyinstaller", "py2exe" etc wherein the other PC need not install the packages like Pandas, Sk Learn etc.
Is there a way that the other PC need not need even have python installed to run and executable will run along with files that the pyinstaller will create?
Advance Thankyou

How to prevent exe created by pyinstaller from being deleted by Antivirus?

I have converted a python project into an exe file using pyinstaller. The basic functionality in the python project is to read files, parse the file contents, and write them into an excel document. The exe file works perfectly fine in my system as I have generated, but when I distribute this exe file to other systems, McAfee antivirus deletes the exe file by displaying the message as "Access denied".
How to handle this situation? I have tried both the commands for pyinstaller and also the auto-py-to-exe tool. But nothing works.
I have also informed the IT team, but they say, there is a potential threat in the exe file.
In issues on GitHub mentioning 'virus' in the PyInstaller repo htgoebel repeatedly states:
Please contact you anti-virus vendor. There is nothing we can do about this false positive.
If your anti-virus vendor considers one of the files included in the PyInstaller distribution or a file generated by PyInstaller to be malicious, there is nothing we can do about this. Even if we'd change our code, they'd change their pattern and the race starts again.
See this mailing-list thread and other tickets for his topic.
So when asking "How to handle this situation?", there isn't much you can do. Like htgoebel said, you can't control what anti-virus vendors match and changing what/how PyInstaller outputs will just be matched to be flagged again later.
You possibly could change to a different anti-virus vendor but that may be out of your control and you'll still have the issue when the package is distributed.
PyInstaller does seem to be the most popular choice for converting a python script into an exe, but there are other choices:
How do I convert a Python program to a runnable .exe Windows program?
When I wasn't able to get around this problem in PyInstaller, I looked for a different tool. I chose cx-freeze over py2exe simply because it had more recent commits on github. It worked great:
python -m pip install cx_Freeze
python -m cx_Freeze test.py
cd build\exe.win-amd64-3.10
test.exe
Output:
Hello world
In case the PyInstaller devs care, my anti virus is CrowdStrike Falcon.

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.

Categories