r/learnpython • u/knightwarrior911 • Jul 08 '20
How to share python exe with people to use the program without having to install python?
Hi All, I have written a my first very basic program for webscraping where it summaries the top 5 most read article and sends a email.
The user needs to enter their email ID and password to login using smtplib and that's all the input that is required.
I wanted to share this with my friends so they can use it at their end without having to install python.
Is it possible to do that? Basically i wanted to know once we write a program how do we create a user friendly front end app?
Many thanks in advance! Any inputs are highly appreciated!
45
Jul 08 '20
You could turn it into a very simple web app using Flask and host it on python anywhere. Users would be able to enter their email address, and the app would use your credentials to send the email. I would set up a new gmail account specifically for this.
13
u/knightwarrior911 Jul 08 '20
Thanks! I do not have much idea about this, kindly forgive my silly questions.
I wanted to know if hosting this web app can be done freely and does my pc need to be turned on to host it 24*7?
32
Jul 08 '20
Yes, it can be hosted for free, and your computer won't need to be turned on. Check out https://www.pythonanywhere.com/
You can develop the code on your computer and then once it's working you can host it there21
1
u/knightwarrior911 Jul 08 '20
Their free account says that one app allowed with restricted access to the internet. Does that mean that the program cannot webscrape?
2
u/Biaswords_ Jul 08 '20
From what I can recall that is true. They have a set of white listed urls you have access to. I would say though, the investment is minimal and it’s such a handy thing to have. I think I have a custom plan and pay $11 a month. And use it daily
2
2
u/CotoCoutan Jul 09 '20
Check out their whitelist. Google PythonAnywhere whitelist, lot of websites on there already so hopefully your website is too.
1
u/OnlySeesLastSentence Jul 09 '20
Ah, looks like I still have to Django it, right?
I was hoping for like a repl.it or trinket.io site, but one that supports larger screensizes.
9
6
u/GrandBadass Jul 08 '20
Highly recommend this suggestion. Also because if you need to update the app then you can change it in the app and not have to regenerate and redistribute the exe file.
1
u/toonarmycapt Jul 12 '20
This isn't a bad idea at all. Learning to build a basic flask app is good, plus you can make an API that someone could use the terminal eg curl yourappurl [email protected].
I've used python anywhere: probableimmunity.pythonanywhere.com/immunity/ , without knowing much in terms of front end web stuff, but plan to figure out heroku at some point soon.
9
u/bootyofbamby Jul 08 '20
If you want some GUI(Graphical User Interface I guess), use pyqt5(you do not need to have a GUI to make an exe).Note that if you use anaconda do not pip install it,it is already installed.but after that It will still remain as py file.So you can use pyinstaller or py2exe to convert py files into exes.
8
u/Llamafu Jul 08 '20
Auto-py-to-exe
It's basically just a gui interface for pyinstaller, but it's way easier than dealing with spec files and messy imports. Best on python 3.5.
7
u/Nexius74 Jul 08 '20 edited Jul 08 '20
Just as a reminder pyinstaller don't work if you use some complex framework like Django or lib2to3. Your best bet (if you're using those kind of framework) is to bundle the python runtime and dependencies in one folder and run the script by using a batch script. Python official web site let you download an embedable python runtime.
Edit: The embedable runtime is only available for windows
4
u/you-cant-twerk Jul 08 '20
You're looking to "freezing your code". Pyinstaller will take care of that. Check out some youtube tutorials.
3
u/johnne86 Jul 08 '20
This is one of those things that make me want to learn JS/Electron or just C# if I want to target Desktop GUI apps. However, everything seems to be heading web based as well these days, might as well learn JS or learn Flask/Django if you stick to Python. I think I'd rather learn to make a Flask app than distribute an .exe, seems more beneficial in the long run.
This Remi project looks interesting for creating web based desktop Python GUIs: https://github.com/dddomodossola/remi/blob/master/README.md
3
Jul 09 '20
Was reading through all the answers and was surprised to see no one mention anything about issues transferring and running compiled python scripts. I'm wondering if it was only me struggling. I've wrote a small script that parses an excel file and creates a new one. Then compiled it with autopy2exe. First issue I've had is that Gmail would flat out refuse to send the email with the attachment. I've either had to use a Google drive share link or spin up my own ftp server to get around that issue. Then with the ftp server, Chrome would flag the file as dangerous so the user would have to take extra steps to force Chrome to download. Lastly, which I barely remember, I think windows will make a big fuss about running the file since it's not signed. That also just requires extra steps in forcing windows to run it.
1
u/RebelSaul Jul 08 '20
I would use PyInstaller.
The resulting files are a littler larger but the process can look as simple as:
# In Terminal
pip install pyinstaller
cd C\files\location
pyinstaller yourprogram.py Many packages are supported too.
1
u/knightwarrior911 Jul 08 '20
Does the last line of code make the program open using pyinstaller?
4
1
u/RebelSaul Jul 08 '20
It packages your python script into a build. I’m the folders created you have an executable file that runs your script.
2
2
2
2
u/savaero Jul 09 '20
Guys, you can publish your code in a free google colaboratory notebook. Check it out...
2
1
1
1
u/skellious Jul 08 '20
So you can make an EXE but another way you can do it is make an installer that installs python alongside your program in the program directory.
A third way is just to include python in a .zip. If you want to make it very easy, include a .bat file that is called runme.bat or something.
1
u/OnlySeesLastSentence Jul 09 '20
CX Freeze with the quickstart script. Make sure you manually put in any files and folders that you added that aren't part of python (images/music/etc)
1
u/Pervert_Chan Jul 09 '20
If you haven't done it yet then I'd like to suggest using cx-Freeze for creating app First install it by using command "pip install cx-Freeze" After installation - cxfreeze-quickstart It will ask for information about the app you want to create like description and version and will create a .py file (setup.py). Go to the terminal and run that setup.py file it will create the installable for you
1
u/iamdarius777 Jul 08 '20
Non relevant to what you're asking but the user needs to turn on less secure app usage or have an app specific password to use your program too right?
0
u/DrBobHope Jul 08 '20
Create a virtual environment. You can use pyinstaller, but I've always had issues with that (especially with newer versions of python).
13
Jul 08 '20
[removed] — view removed comment
4
u/GrooseIsGod Jul 08 '20
I'm new to computer science stuff. Why?
8
u/PapaJohnX Jul 08 '20
Not so much computer science, but interpreted languages (like python) need to be run using interpreters (e.g. CPython) which converts the python code as we understand it -> Python bytecode -> low-level machine instructions. In compiled languages, the executable that is built is already machine code.
Some might disagree with what u/tux-deluxe w.r.t. compiled languages being more appropriate for creating a program that can be given to anyone. For example, lets say I create a C++ executable targeting Windows, my linux user friend cannot run my program natively in linux. However, if I create a python script, anyone who has a python interpreter can run my code, regardless of OS, architecture, etc.
1
173
u/sme272 Jul 08 '20
Write your program and use pyinstaller to turn it into an exe when you're done. The exe will only work on systems that have the same operating system as the one it was created on, so if your friends use different OS's you'll need to create a virtual machine running that OS on your computer and create a separate exe for them.