Gimp won't launch properly from a shell script in OSX - python

I'm using MacOS Mojave (v. 10.14.16, latest version with all updates) and I'm running Gimp 2.10. I made a Python plugin that works great from the command line terminal, but I can't it to work from a shell script. The plugin opens an XCF template, adds an external JPG as a new layer, positions the external JPG using x and y offsets, flattens, and then exports a new JPG that shows the external JPG in the template.
Background info:
In OSX just typing “gimp” at a terminal did not launch Gimp, so I created an alias in the .bash_profile in my home directory (/users/TimB) using the steps described here: https://mattmazur.com/2012/01/27/how-to-add-terminal-aliases-in-mac-os-x-lion/. The alias reads as follows:
alias gimp=”/Applications/GIMP-2.10.app/Contents/MacOS/gimp”
My alias works great from the command line terminal, but not from a shell script.
In my shell script just trying to execute “gimp” on a line does not launch Gimp so I believe my alias is not recognized in the script. Therefore, to launch Gimp along with my Python command line arguments I do this:
/applications/gimp-2.10.app/contents/macos/gimp -idf --batch-interpreter python-fu-eval -b "import sys;sys.path=['.']+sys.path;import OAFE_PARAM;OAFE_PARAM.open_add_flatten_export('/Users/TimB/Desktop/xcftemplate.xcf', '/Users/TimB/Desktop/jpg_to_add.jpg', 2060, 410, '/Users/TimB/Desktop/')" -b "pdb.gimp_quit(1)"
This does not work. My command line arguments are ignored, and I see a message "GIMP-Warning: The batch interpreter 'python-fu-eval' is not available. Batch mode disabled."
To troubleshoot I tried just launching the Gimp UI from a shell script and even that doesn't work properly. It loads strangely with broken icons (see image below). Any ideas what I can do to fix this? Am I doing something wrong in how I'm trying to launch Gimp?
Gimp UI screenshot
Here's my script to launch Gimp that fails:
#!/bin/bash
arg1="/Users/TimB/Desktop/xcf_template.xcf" #XCF file to open
arg2="/Users/TimB/Desktop/jpg_to_add.jpg" # JPG to insert
arg3=2060 # x_offset
arg4=410 # y_offset
arg5="/Users/TimB/desktop/" # save location
echo
echo "arg1 is" $arg1
echo "arg2 is" $arg2
echo "arg3 is" $arg3
echo "arg4 is" $arg4
echo "arg5 is" $arg5
/applications/gimp-2.10.app/contents/macos/gimp -idf --batch-interpreter python-fu-eval -b "import sys;sys.path=['.']+sys.path;import OAFE_PARAM;OAFE_PARAM.open_add_flatten_export('/Users/TimB/Desktop/xcftemplate.xcf', '/Users/TimB/Desktop/jpg_to_add.jpg', 2060, 410, '/Users/TimB/Desktop/')" -b "pdb.gimp_quit(1)"
UPDATE (3-27-2021):
I followed Mark's suggestion by removing my alias, ensuring that /usr/local/bin is on my PATH, and I created a symlink with sudo ln -s /applications/gimp-2.10.app/contents/macos/gimp /usr/local/bin/gimp. That still lets me launch Gimp by typing "Gimp" in terminal, but it still fails from within a shell script. I get this message.
The shell script is very simple:
#!/bin/bash
gimp
Here's the error I get:
../../../../gtk/source/babl-0.1.78/babl/babl-internal.h:214 void babl_log(const char *, ...)()
WARNING: the babl installation seems broken, no extensions found in queried
BABL_PATH (/Users/distiller/gtk/inst/lib/babl-0.1) this means no SIMD/instructions/special case fast paths and
only slow reference conversions are available, applications might still
run but software relying on babl for conversions will be slow
2021-03-27 11:27:22.180 gimp[85955:1451980] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead.
Cannot spawn a message bus without a machine-id: Unable to load /var/lib/dbus/machine-id or /etc/machine-id: Failed to open file “/var/lib/dbus/machine-id”: No such file or directory
../../../../gtk/source/babl-0.1.78/babl/babl-internal.h:222 void babl_fatal(const char *, ...)()
const Babl *babl_format(const char *)("CIE Lab double"): not found
sh: gdb: command not found

I got the same error today on macOS 12.4, Monterey. Gimp and babl installed through brew. Even when I run it as:
BABL_PATH=/usr/local/lib/babl-0.1 gimp
it still fails.
../babl/babl-internal.h:222 void babl_fatal(const char *, ...)() const Babl *babl_model(const char *)("RGBA"): you must call babl_init first
Unable to find Mach task port for process-id 17902: (os/kern) failure (0x5).
(please check gdb is codesigned - see taskgated(8))
/tmp/babl.gdb:1: Error in sourced command file:
No stack.
The gdb error is not related. I just didn't sign it yet. If I start gimp by clicking on the icon then it works though. But not from the cmdline.

Related

command not found when using makefile to run batch file on Windows 10

When I try to run a makefile (type "make test" in terminal) which runs a batch file I get the equivalent error:
cd directory_path && test.bat
/bin/sh: test.bat: command not found
make: *** [makefile:58: test] Error 127
The makefile is:
.PHONY: test
test:
cd directory_path && test.bat
python path/test.py
(I changed names of the batch file, the directory path, etc. to try and make things more generic)
I can manually type "cd directory_path" and then "test.bat" and those both work. This makefile works on other systems. It only doesn't work on mine. I think it is an issue with how I installed Cygwin and how I run "make.exe".
I can use make to compile C code, but I also get an error trying to use make to run python scripts. The makefile from before also has a command for python path/test.py. This also isn't working on my system. If I delete the batch file line, but keep the python command it throws the error:
python path/test.py
make: python: No such file or directory
make: *** [makefile:59: test] Error 127.
I don't understand why it throws the error of no such file or directory since the path leads to the file, and if i put the python script in the same working directory as the makefile then it still can't find it.
Any ideas/solutions on these problems? Thank you!
EDIT:
Doug Henderson:
I started a cmd prompt at the place with the make file and entered all of these commands in
uname -a
CYGWIN_NT-10.0 james-mobl2 3.1.6(0.340/5/3) 2020-07-09 08:20 x86_64 Cygwin
which make
/usr/bin/make
make -v
GNU Make 4.3
Built for x86_64-pc-cygwin
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
which python
which: no python in
(/cygdrive/c/Program Files/AdoptOpenJDK/jdk-8.0.252.09-hotspot/bin:
/cygdrive/c/windows/system32:
/cygdrive/c/windows:
/cygdrive/c/windows/System32/Wbem:
/cygdrive/c/windows/System32/WindowsPowerShell/v1.0:
/cygdrive/c/windows/System32/OpenSSH:
/cygdrive/c/Program Files/Git/cmd:
/cygdrive/c/Users/james/AppData/Local/Microsoft/WindowsApps/python:
/cygdrive/c/Program Files/PuTTY:
/usr/bin:
/cygdrive/c/Program Files/AdoptOpenJDK/jdk-8.0.252.09 hotspot/bin:
/cygdrive/c/Users/james/AppData/Local/Microsoft/WindowsApps)
(I cleaned up the output a little to make it more legible). This and which test.bat are the only commands that failed.
python -V
Python 3.8.5
The change directory changed correctly
which test.bat
which: no test.bat in
(/cygdrive/c/Program Files/AdoptOpenJDK/jdk-8.0.252.09-hotspot/bin:
/cygdrive/c/windows/system32:
/cygdrive/c/windows:
/cygdrive/c/windows/System32/Wbem:
/cygdrive/c/windows/System32/WindowsPowerShell/v1.0:
/cygdrive/c/windows/System32/OpenSSH:
/cygdrive/c/Program Files/Git/cmd:
/cygdrive/c/Users/james/AppData/Local/Microsoft/WindowsApps/python:
/cygdrive/c/Program Files/PuTTY:
/usr/bin:
/cygdrive/c/Program Files/AdoptOpenJDK/jdk-8.0.252.09 hotspot/bin:
/cygdrive/c/Users/james/AppData/Local/Microsoft/WindowsApps)
I added cmd /c test.bat to the makefile and it worked, but I've also had the batch file run on different systems without that addition. I also have a lot batch files in the actual makefile so this solution works but isn't ideal. It also didn't fix the python script not running.
I didn't initially have cmd.exe in my path, but I added it before entering those commands.
I'm not sure what you mean by starting my PATH in bash with /usr/bin;/bin;THE_REST
MadScientist:
I was manually entering it into a Windows Terminal. Is it possible to have Cygwin invoke a Windows command.com shell?
What I did was go to directory that contained the makefile. Open a windows terminal by typing 'cmd' in the address bar. I would then type 'make test'. That obviously led to the issues. I then went through and manually entered the commands I thought the makefile was supposed to invoke. So I entered 'cd directory_path && test.bat'. This ran.
Matzeri:
I don't really know. I'm completely new to POSIX, etc. I'm guessing I'm using Windows style, and judging from other responses, I'm trying to use Cygwin to do a non-POSIX style.
Thank you, everyone for responses!
Make sure cygwin is installed with basic packages --> Some basic packages not installed with cygwin try below link to install some basic package, uninstall the cygwin and install it again with following basic package :
https://wiki.usask.ca/display/MESH/Running+Python+from+the+Cygwin+Terminal#RunningPythonfromtheCygwinTerminal-Cygwin
make sure cygwin's bin folder is added to your environment variable (e.g., C:\cygwin64\bin)
If cmd /c test.bat works then . is probably not in your PATH. Always do ./test.bat when you want to run something in the current directory. Never count on the PATH unless you have set it yourself. Also make sure the file is executable. chmod +x test.bat

Invoking g++ via `subprocess.run` in Python causes "exec format error" in executable

Using Python 3.7, I am trying to invoke g++ to compile and build a C++ file via
#!/usr/bin/env python3
import subprocess
if __name__ == '__main__':
subprocess.run(
executable="/usr/bin/g++",
args=["/some/path/source.cpp", "-std=c++17"],
shell=True
)
When I run the script, the executable builds. I then chmod u+x it. However, when I try to execute the executable, it fails and says:
-bash: ./a.out: cannot execute binary file: Exec format error
I've read some other posts regarding this error however none are applicable. For some reason, this method fails, however when I run g++ natively in my terminal, it works as expected.
Edit: When I invoke file a.out, the output is
a.out: ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), not stripped
Appreciate any help, thanks!
The executable parameter to subprocess is only rarely needed. With shell=False, it overrides args[0] as the program to run (allowing argv[0] to be customized, as for a login shel). With shell=True (which should be avoided when possible, partly because it doesn’t do what you think with your carefully separated args list), it replaces the implicit /bin/sh invoked to run the command. The standard option to run one command is -c, so you ran
/usr/bin/g++ -c /some/path/source.cpp -std=c++17
which indeed produces a relocatable (i.e., a .o file). a.out is not the normal name for such, but perhaps it’s a fallback when the directory containing the source is not writable.

Start python file in Swift

I want to start a pythonscript by pushing a Button in a swift macOS application. I come up with:
let process = Process()
process.launchPath = "/usr/bin/python3"
process.currentDirectoryPath = "\(NSHomeDirectory())" + "/PycharmProjects/untitled5"
process.arguments = ["myscript.py"]
process.launch()
but I get "launch path not accessible" error by executing. If I change launchPath to:
process.launchPath = "/usr/bin/python"
everything works fine, but now I getting python compiling errors because myscript is written in python3.6.0, I have to use python3 because of using a library.
When I open Finder and go to "/usr/bin/python3" it says not found, but python3 is installed, I used it in Pycharm and I'm also able to start python3 in terminal.
In terminal "python3 ~/PycharmProjects/untitled5/myscript.py" works.
On your terminal type
which python3
this will return the path that is accessed when you run python3 from the command line

How to prevent command prompt ( windows ) from opening file when typing command?

I download source code of my app from google appengine using this command in cmd:
appcfg.py download_app -A <your_app_id> -V <your_app_version> <output-dir>
But, instead of running the command, it opens the file "appcfg.py". So I don't know what to do now.
Sounds like python files are associated with an editor instead of with the python interpreter.
If so you'll have to change the associations for .py files (found in folder options), or call the python interpreter:
C:\path\to\python appcfg.py download_app -A -V

cannot compile cpp files under the python pyc script file

I am trying to compile & execute my hw cpp file under the python script file which we are given by lecturer. the how-to-manual.pdf he sent us it says use:
c:\>python ./submit.pyc problemID -u username -p password -b //submit.pyc is already given to us
and here is the manifest.txt we are given:
[main]
problem = gc
build =
g++ main.cpp -o solver
run =
./solver %f
my cpp file works normally like this:
./solver input_file
However, I am trying (I have to) to do this under the windows OS. I have Python 2.7.x installed and python.exe is in the Command PATH. I can't run it under the linux ssh sytem because there is 2.4.x python installed and I can't touch it (school's system).
Anyway, when I execute the line above, it returns me:
Command execution failed:
g++ solver.cpp -o solver
I think I told everything I can. So, any idea that what I have to do else? except asking to lecturer:)
For the above to work it needs to be able to find g++ so you need to add the directory that it resides in to the PATH environment variable. This can be done from within your python script or on the command line with:
path=Where\g++\lives;%path%
This will only apply within the current DOS session.
Or you can add it permanenty through system settings->advanced settings->environmental variables
You could also look at using a python virtual environments on the schools linux system.

Categories

Resources