How to use CLI for apps on Windows? - python

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

Related

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

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

Make a Python app package/install for Mac

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.

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.

execute python script when directory is not empty - Directory Monitoring

I have a python script that converts images and videos withing a directory.
The problem, the python script executes manually but I need the script to execute automatically when a file is dropped into the directory under a linux platform.
What would be the best way to set a python script to watch/monitor a directory?
I've looked into many options but not sure which one just simply sets the script to execute when files are dropped into a directory.
Thank in advanced
The 'clean' way to do this is using the inotify system. There is the Pyinotify project if you want to use Python to interface with it.
You don't have to use inotify directly though - there are tools like icrond you can hook into. In fact, the person at that link looks to be trying to do something very similar to what you want - check it out.
Brute force, you could use watch, though that just runs a command periodically, not only when something changes.
Check out PyInotify
Or for an easier example:
PyInotify Tutorial
Use pyinotify:
https://github.com/seb-m/pyinotify
A tutorial is here: https://github.com/seb-m/pyinotify/wiki/Tutorial

Categories