How-to Launch Android Python Script via Shortcut on Homescreen - python

I've scoured the interwebs and couldn't find anything with python, android, and "shortcut" or "home-screen" to appear on the same page. I have pydroid3 installed, working great. I'd like to have a shortcut (ideally on the home-screen) that I can tap once and have it run without opening the IDE for editing.
Making a shortcut to the file, or opening a source file in the file manager will at best just open it in the pydroid3 IDE, at worst state "this file type is not supported."
At the beginning of the script, I have tried putting "#!/user/data/../pydroid_dir/python", but alas the OS doesn't realize I mean to run it directly in the python interpreter. Any solutions or alternative lines of thinking are appreciated!
EDIT
I'm running an unrooted android 9 PIE. I wanted to provide some more details but not quite a solution for any readers. Check out related question: How to create a homescreen shortcut to launch a shell script?. Closest I got was trying SManager which allows you to create a homescreen shortcut to a shell script. Your shell script could be hardcoded to call python on your script:
/path/to/python /path/to/python/script
Unfortunately, if you're phone is not rooted, you may not have permission to execute whatever version of python you're calling outside of the context of the app it was installed for. Also, you have to ensure that your shell and python scripts reside in an appropriate place for execution. If your phone is rooted, SManager seems to have options to let you run the script as root.
pydroid3 allows me to run scripts residing on my internal storage as well as lets them read and write files at that location. That's why I was hoping that there was a pydroid way to create a shortcut (or an alternative python app that does this) since it has appropriate privileges.

QPython OL lets you create home screen shortcuts to python scripts on Android. First tap on the 'Q' icon at the top of the main screen (it took me a while to realise this was a button), then long-press on the script you want. This should give you a prompt to create a shortcut, as in the screenshots below.
QPython 3L also claims to have similar functionality when you long-press a script in its 'Programs' section. At time of writing (Jun 20) this seems to be broken.
I've not tried Pydroid myself, but haven't come across anything claiming it could create script shortcuts either.

You can use Termux:Widget as a command line to execute a python script. In Termux you can not create GUI with tkinter. You have to launch X-Server with VNC Mobile client. The widget is like a small shell prompt.

Related

Can manim be used in pycharm?

I have been programming with python for about half a year, and I would like to try manim ( the animation programme of 3blue1brown from youtube), but I am not sure where to start. I have not installed it, but I have tried to read up on it. And to be honest I do not understand much of the requirements of the program, and how to run it.
Google has left me without much help, so I decided to check here to see if anyone here is able to help.
From what I understand, you run manim directly in python and the animations are based on a textfile with code i assume is LaTex. I have almost no experience with python itself, but I have learned to use it through Thonny, and later Pycharm.
My main questions are: (Good sources to how to do this without being a wizard would be really helpful if they exist☺️)
Is it possible to install manim in pycharm, and how? Do i need some extra stuff installed to pycharm in order to run it? (I run a windows 64-bit computer)
If i manage to do this in pycharm, Will I then be able to code the animations directly in pycharm (in .py or .txt files), or is it harder to use in pycharm?
All help or insights is very appreciated😅 As I said I am not extremely knowledgeable in computers, but I am enjoying learning how to code and applications of coding😊
I recommend you this playlist
I always uses pycharm for manim.
Firstly i setup python interpreter by just open File->Settings->Projet->Project Interpreter then just press on little gear icon to add python interpreter to Existing environment and locate C:\Python3x\python.exe
Then just open a terminal from left-down corner and run some basic commands to run manim as mentioned in tutorials or manim github page.
Something that works nicely for me is to run manimgl.exe from Python in PyCharm using the subprocess module. It also goes well with using the run shortcut while iterating with small edits.
I like to do this from the script in which my main scene is defined, for example, I have main.py which defines MyScene:
from manimlib import *
class MyScene(Scene):
def construct(self):
...
if __name__ == '__main__':
import subprocess
params = 'manimgl main.py MyScene -c WHITE'.split()
subprocess.run(params,
check=True,
capture_output=True,
text=True)
# Possibly look at captured output here
The code inside if __name__ ... does not execute when the same script is loaded by manim. What is nice is that one can easily add automation steps before or after the actual execution if needed and it keeps everything related in a single script.
Edit: I also end the animations in the construct() method of MyScene with exit() to terminate the preview. I honestly don't know if this is good practice, but it works well for my usage pattern.
Note that this does require that manimgl.exe reside somewhere that is in your path, in my case (Windows) I installed this for my global Python interpreter. I followed the instructions on GitHub and it works for me because the following is in my path:
C:\Users\XXX\AppData\Local\Programs\Python\Python38\Scripts\
It may vary depending on where your Python is installed. For a venv, you could do something like:
params = '.\venv\Scripts\manimgl.exe ...'.split()
Yes, you can
1.Write your code in pycharm
2.save it
3.copy that .py file to where you installed manim. In my case, it is
This pc>> C drive >> manim-master >> manim-master
4.select on the path and type "cmd" to open terminal from there
Type this on the terminal
python -m manim -pql projectname.py
This will do.
To play back the animation or image, open the media folder.

Python- Alternative terminal in Atom text editor

Right now I'm running Python in Atom with Platformio as my terminal. First off, what's the keyboard shortcut to run the file? Secondly, is there a better terminal package out there? I'd like more features such as right clicking and selecting run the file or something that makes running the file easier (maybe a run button). I switch between files quite frequently so I'd like an alternative other than using the up arrow to run previous command.
I use Atom for python. The best terminal plugin I have found is Platformio. I have a plugin named script that allows me to run python scripts from the editor window. The command also has a shortcut to speed up the process. Load script and it will appear under the packages menu. It also defines the shortcut for 'run script' as the command-I keys.
Lately I've been running python script using the Hydrogen plugin. This allows in-line plotting along with running your script. Answers and plots appear in the editor pane. Its very nice if you have to plot.

How to make it extremely easy to run a python script for a user

I built a python/bash application for OSX that I want to distribute to non techsavvy users. My problem is how to get the user to initially run my python script. The script sets up a cron job so the user never has to do anything again but the user MUST run it the first time. The issue is that python and bash scripts default to non-executable when unzipped. As of now I have instructions in the readme.txt for the user to open the terminal and copy and paste the command which chmods the script and runs it for them. However is there anyway I can accomplish this without having the user open the Terminal? Ideally the user could just double click the python script and have it run. Thanks.
Sometimes being user-friendly warrants using platform-specific features. In this case, the Mac OS X "Installer" system: http://en.wikipedia.org/wiki/Installer_(OS_X)
Rather than a .zip file, you can create a .pkg file which users can download and install just as they would any other program native to OS X. This should give them a familiar experience, and you can make the .pkg file do what you need behind the scenes.

Loading code from editor into PyCharm terminal

I've just started using PyCharm, and am consistently pleasantly surprised by its tools and configurability. I know that in PyCharm, you can load code from the editor into a Python console (see https://www.jetbrains.com/pycharm/webhelp/loading-code-from-editor-into-console.html). However, the remote console I'm using in PyCharm is very slow.
If I access python on the remote machine directly via ssh, it has no performance issues. As such, I'd like to just open the remote version of python via PyCharm's Terminal, and execute code in the terminal from my editor.
However, I haven't found any key bindings (or options) that let me automatically load code -- it's a manual copy and past process for now. When I try to create a keyboard shortcut to do this, the option isn't available. Is there a method to create a keyboard shortcut to load code from the editor into the terminal?
The only way to create such a shortcut by yourself is by writing a plugin to PyCharm. PyCharm plugins are written in Java, so I don't know whether this sounds like an appealing option for you. Alternatively, you can file a feature request at http://youtrack.jetbrains.com/ asking for this feature to be added.
Note that you can set up a run configuration that will run your code for you on a remote interpreter without going through a console. Have you tried this? Is it also slow?

Python curses Redirection is not supported

I am trying to use Curses in PyDev in Eclipse in Win7.
I have installed Python 3.2 (64bit) and curses-2.2.win-amd64-py3.2. When I input the following testing codes into PyDev:
import curses
myscreen = curses.initscr()
myscreen.border(0)
myscreen.addstr(12, 25, "Python curses in action!")
myscreen.refresh()
myscreen.getch()
curses.endwin()
It did not show any syntax error, so I think the curses was installed correctly.
However, when I ran it as Python Run, the output showed: Redirection is not supported. I do not know where this problem comes from. I googled a lot but can't find related information.
Recent PyCharm versions (I am currently running 2017.2, not sure when this option was added, or if it has been there the entire time) have the option "Emulate terminal in output console". Curses works with this option checked.
You cannot expect to use curses with a non-terminal.
Probably you get this because you are running the script from inside an IDE, like PyCharm or any other.
All IDEs do provide consoles that are not terminals, so that's where the problem comes from.
For a Pycharm user the solution given by codeape works fine :
Snapshot
You can't use any IDE to run python files with the curses package. I used to run in pycharm and naturally couldn't run.
Change to the command line to run:
for testing follow my following steps
on desktop open notepad and copy paste the code and save it as filename.py
open command line change directory to desktop use below command cd Desktop and hit enter type python example.py and hit enter, your program will definitely run
My workaround is to create a Run Configuration that calls a curses script. The little overhead is worth not having to switch to the terminal and manually run the script hundreds of times a session. I use Intellij but I imagine the process should be similar in PyCharm.
The desired result is the convenience of a button to run the script:
First create a script that calls the entry script, for instance:
ptyhon name-of-script.py
Then, to create a configuration for each script:
Go to Edit configuration.
Click the plus button and add a Shell Script.
Enter the path to a shell script.
Here is a picture of a directory with a couple of sample scripts.
I use this process to view my progress. My curses scripts are very modest so fortunately I can live without a debugger.

Categories