Make a Python app package/install for Mac - python

I have developed an application for a friend. Aplication is not that complex, involves only two .py files, main.py and main_web.py, main being the application code, and _web being the web interface for it. As the web was done later, it's kept in this format, I know it can be done with one app but not to complicate it too much, I kept it that way. Two two communicate with some files, and web part uses Flask so there's "templates" directory too.
Now, I want to make a package or somehow make this easier for distribution, on a OSX system. I see that there is a nice py2app thingy, but I am running Windows and I can't really use it since it won't work on Win. I also don't know will py2app make problems since some configs are in text files in the directory, and they change during the runtime.
So, I am wondering, is there any other way to make a package of this, some sort of setup like program, or maybe some script or something? Some simple "way" of doing this would be to just copy the files in the directory in the "Documents", and add some shortcuts to the desktop to run those two apps, and that would be it, no need for anything else. DMG would be fine, but not mandatory.

I believe what you are looking for is to add: #!/usr/bin/python to the first line of your code will allow your friend to just double click on the file and it should open. Just as a warning osx does not tell us what version and as such what version of python and what standard libraries are going to be present.
Also, just make sure that if they have played around with their settings to much and they double click on python it does not work they will have to choose to open the file in "terminal.app" in the Utilities Applications folder (/Applications/Utilities/terminal.app)
The other idea is borrow a mac and compile it with the py2app program that you already mentioned. Otherwise there is no generic binary file that you will be able to compile in windows and have run on mac.

Related

How to change default program/ file associations to open files using python script?

I need to make a way to install my code, and set default programs depending on file type.
I've been trying to make my python program easy for people who know nothing about python or programming to use.
As an alternative to an exe I want to make a script to do everything, including putting a shortcut to the python code on the desktop and a start menu folder.
The thing is I need to make sure that .py files automatically hey opened by python, and not the software, psychopy, which the user will install.
Is there a way to use python to change the default program for a given file type?
I've already tried:
Py2exe: I get errors (see post history)
Pyinstaller: I get different errors.
The errors with py2exe seem almost irresolvable.
I've used pyinstaller before and it worked. It won't easily work with this code because it doesn't work with an updated library/package I need. I have library b which depends on library a being up to date. So I can't revert back to a setup that I know how to make work.

How to use CLI for apps on Windows?

So basically, I'm trying to open an app on Windows installed from Microsoft Store through CLI. Like lets say for example, opening Spotify app on Windows. How do I do that? Tried googling around but couldn't find any. You can also suggest your answer for Python if that works.
you could simply make a .bat file. look up batch files, there's lots of crazy stuff with you can do with them, and then there's powershell which is even more versatile.
run_program.bat
start C:\path\to\program.exe

Edit file while executing in PyCharm

I am working on a project in PyCharm that involves extensive computations, with long runtimes.
I would like to do the following: I come up with a version of my code; then run it, then I edit the code some more; however, the run I started before still only uses the old version of the code (i.e. the snapshot at the point of running).
Is this possible in PyCharm?
I run my project by selecting the Run 'projectname' option from the Run menu.
I understand the run works by pre-compling the .py files to .pyc files stored in the __pycache__ folder. However, I don't know the following.
Will saving the file in PyCharm cause the .pyc files to be replaced by new versions? This is something I want to avoid since I want one run to only use one snapshot of the source tree, not multiple versions at different points of execution.
What if some python class is only needed, say, 20 minutes after the run has started. Will the .pyc file be created at the beginning of the run, or on-demand (where the corresponding .py file might already have changed)?
I use PyCharm in my classes. My experience is that the all the required code, including the imported modules, are compiled at runtime. If you change anything in that suite you need to start running from scratch for it to take effect.
I'm not a professional programmer so my experience is with small apps. I'd love to hear form an expert.

Pyinstaller's 'onedir' mode creates too many files

I am "compiling" my Python application for Windows with PyInstaller 2.1. I initially tried using onefile mode, but onefile takes a long time to startup (decompressing wx and matplotlib). With the onedir mode it's pretty fast (only a little bit slower than native python).
So I want to use onedir mode for faster startup times, but for the end-user it's difficult to find the actual *.exe file inside the huge amount of files located in the main directory (there are 98 files including the actual executable and it's manifest).
I want to make sure a non tech-savvy user can easily "double-click" the executable and work with this program (ease and portability) without a long disclaimer to "just ignore" the 97 other files there.
Is it possible to move all those "distracting" files into a subfolder? Or are there other ways to make it easy for the end-user to run this program?
maybe you could use onedir. The resulting folder you can put anywhere and create a shortcut to the user where it is more comfortable.
Easiest way to reduce the number of files created in --onedir mode would be to create a virtual environment and install only the necessary modules.
You could use some software to pack it into a one-file installer, such as Inno setup.
You could also try to delete some files one by one (if the executable fails just undelete it). I figured out that almost half of the files can be deleted with the executable working fine.
Download Inno Setup from here.

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

Categories