Make a Mac .App run a script on running of said .App - python

I have a script (Shell, chmod-ed to 755. Python is in the script, meaning not run from an outside .py file) that is executable. It works when I run it. How can I make a .app that executes said script on runtime? I have a simple .app that has this structure: APPNAME.App>Contents>MacOS>script
This does not run. Is there any way I can piggyback a script onto another application, The Powder Toy, for example? I'm not new to OSX, I just don't have root privileges and can't install XCode.
Rembember, I can't install anything from source or use setup scripts, effectively annihilating py2app as an option.
EDIT:
This answer is courtesy of mklement0. Automator lets you choose the environment to run your script, type it in, and bundle it into a .app, removing the need for a shell script.

Run Automator and create a new Application project.
Add a Run Shell Script action.
In the Shell: list, select the interpreter of choice; /usr/bin/python in this case.
Paste the contents of your Python script into the action and save the *.app bundle.

if your using applescript, just save it as a bundle by save as, and click the drop down saying script, change that to bundle i think. after that, click on the bundle icon in apple script and drag the script to the folder you want. to run it put your run command in and drag the script that you placed in the bundle folders before in the directory slot of the run command. i can not give you anything exact due to the fact that i am not on my mac, but i am giving you the best i know.

Related

python packaging in exe and bin

Please tell me how to package my project correctly in exe and bin.
I have tried to do it via nuitka on Linux and virtual Windows.
On Linux, I use this command:
python -m nuitka --standalone --follow-imports --output-dir=relize-linux --enable-plugin=tk-inter --enable-plugin=numpy --disable-console --product-name=aigod --linux-icon=aigod.ico --linux-onefile-icon=aigod.ico main.py
On the virtual Windows environment, I use this command:
python -m nuitka --standalone --follow-imports --output-dir=relize-windows --enable-plugin=tk-inter --enable-plugin=numpy --windows-disable-console --windows-icon-from-ico=aigod.ico --windows-product-name=aigod --lto=no main.py
Compiling and running the binary, both give me the same result (not opened), a pop-up window, supposedly a startup error.
The main file is just a GUI menu on tkinter, although this menu should have shown.
I also tried pyinstaller, but still cannot run the binary correctly.
I can't figure out why this happens.
upd-----------------------------------
I managed to compile the project using the command:
python -m nuitka --standalone --follow-imports --output-dir=relize-linux --enable-plugin=tk-inter --enable-plugin=numpy --disable-console --product-name=aigod - -linux-icon=aigod.ico --include-package-data=classify --include-package-data=data --include-package-data=models --include-package-data=segment --include-package- data=utils main.py
But the catch remains, I have additional scripts that are called via import script2 at the right time. As I understand it, their dependencies were not determined and the project did not introduce them, plus they are in the main folder along with the main script. I tried putting them in a separate folder and trying to account for them with --include-package-data=otherfiles, but that didn't work. Tell me how to take them into account too, they are important because the main script is just a menu, and the rest of the scripts do all the work. Of course, I will try to look at what it writes in the console during the next package, since in this one I indicated without a console.

Why I can’t run exe file on other pc

I had created with tkinter an application.
this application (python.py) contains a button, by clicking on the button it calls scripts (scripts that I have already created before) and executes them.
I was able to convert python.py to python.exe with pyinstaller (pyinstaller --onefile python.py)
after this step I put my python.exe and pycache and all the scripts (with extensions py) that I should use on my application in a single folder and open the folder in NSIS … so you can send it to another user who doesn't have python
On other pc : the application opens but as soon as I click on the button to have the execution of the scripts I have an error
python was not found; run without arguments to install from the Microsoft store, or disable this shortcut from settings > Manage App Execution Aliases.
I fix it with disable app python on manage app execution aliases. (I don’t know if it correct), but I tried to run it again and I have this error
python’ is not recognized as an internal or external command, operable program or batch file.
yet everything works fine on my pc
knowing that I work on windows
maybe i forgot a step?
Python interpreter is not installed on the target PC. Bundle your executable with all dependency libraries necessary to run your application on any windows PC. Also note that your windows version matters too.

How to run the python shell inside a terminal in Windows?

I've scrolled the internet all over and theres no simple, clean explanation for this. How can I open the Python shell, but inside a terminal window such as CMD? I have an application for it, but want to run it inside a terminal, so I can practice Python code inside my IDE like VS code.
If you have a reasonably new version of Python you need to run py.exe (or just py) instead of python.exe, because the real python executable (python.exe) is not in your path environment variable by default, whereas py.exe is in the /windows directory and thus automatically in path.
So to run your script type py yourscript.py from the directory of your script. If you just run py it will start the interactive interpreter.
Look e.g. at https://www.python-course.eu/python3_execute_script.php
Under the title Start a Python script (almost at the beginning)
there is an instruction. Just write from the command prompt:
python,
a space,
and the filename containing your script, with .py extension.
As in each command, press Enter and your script will be executed.
Of course, I assume that you have installed Python on your computer.
If this is not the case, start from installing it.
I have quite a new Python version installed (3.6.5) and start Python
writing just python. Writing just py also does the job, but (IMHO)
it is not necessary.
If you want to start Python interpreter and play around with some
Python commands, write just python and Enter. The interpreter will
start and display its own command prompt (>>>).

Python script that can run from OSX Finder and Windows Explorer

I have a bunch of useful Python3 scripts that I use in different OS environments. They run fine when called from the terminal but I want to run them from both Windows Explorer and OSX Finder. In Windows, that is not an issue as the *.py files get associated with the installed interpreter.
For OSX, I am having some problems. I tried using the shebang line.
#!/usr/bin/python3
But Finder doesn't recognize it as a script. How do I make Finder recognize *.py files as scripts? I am interested in maximum portability with as few OS modifications as possible.
Also I explicitly specified the interpreter location above. It will be in different locations for different OSes. Is there a way to make it multi-OS so that if it doesn't find it in one location, it will try another? Say if I want to run it from one of Ubuntu's GUI File Manager.
EDIT: Here's more info on my use case. I want to go to a new computer and git clone my repo of Python3 scripts and be able to run them from within the GUI file manager with minimal changes to the new computer.
To make the script more portable use #!/usr/bin/env python3 as shebang. Side effect will be that it will run the first python3 interpreter it finds in the $PATH (Unix StackExchange question on that subject)
To run the script from the finder try to chmod the file. i.e.
chmod +x FILE
Found another possibility here: Link to the Blog
Make this the first line of your Python script "#!/usr/bin/env python"
Change the extension of the script file to ".command" i.e. my_python_script.command
In Terminal make the Python script file executable by running "chmod +x my_python_script.command"
Now when you double click the Python script in Finder it will open a terminal window and run.
Alternative I found would be this but it needs system modification: Superuser question

Installing python 2.7.2 on Debian 5.0

I'm having some trouble running the ./make command in my debian command line to install python 2.7.2.
I untarred my download from Python.org and ran ./configure which appeared to have worked fine. Unfortunately when I type in ./make I get the following error:
./make: No such file or directory
Not sure why this occurs, but I'd like to get an updated version of python to continue learning the language.
Thanks for your help,
Andy
When you type ./configure, it runs a executable script in the current directory (labeled with a .) called configure.
Make is an executable file, usually located somewhere like /usr/bin, which uses a file in the directory to run a bunch of commands depending on whether files are up to date.
When you just type make, your shell (the program that handles all your commands and sends their output to the terminal) will go looking through all the directories in the PATH environment variable to find an executable file called make, and run the first one it finds. But, when you type ./make, you're actually telling it to try and run an executable file in the current directory, called make. (It uses this approach, not searching the PATH variable, whenever you put a / in the command.)
You can use the . anywhere you could use a normal directory to specify the same directory, so for example: /usr/bin/././././ is the same as: /usr/bin. Similarly, you can use .. to specify the directory above, so /usr/bin/../bin/../bin/../lib is the same as /usr/lib.
So, after running the configure script located in ./, which generates a so-called makefile, you run the system wide version of make, located where ever, by just typing make, which uses the makefile to build the package.
Also, you can use the which command to find out where the command that'll run when you enter a command by itself - for example, which make.
(Apologies if any of this is condescending, I was going for completism. Also, I may have overused the code tags...)
its not ./make
try
"make"
as it is

Categories