Termux says "'Bad Interpreter: No such file or directory" - termux

I have a problem and hope someone can help me. I am currently trying to write a script for Termux or Termux:Task. My script currently looks like this:
#!/data/data/com.termux/files/usr/bin/bash
cd /./sdcard/www/public/
wp post list sleep 5
Every time I load the script I get the following error message:
/data/data/com.termux/files/usr/bin/wp: /usr/bin/env: bad interpreter: No such file or directory.
I've been looking for a solution to my problem for hours, unfortunately without success.
I am using an extension for Termux called "WordPress CLI". When I start termux and enter the commands individually, everything works. But as soon as I write the commands into a sh script and start it doesn't work anymore. :(
Can anyone help me?
Thanks a lot

This is simple error you can fix it by replacing !/data/data/com.termux/files/usr/bin/bash. With #!/data/data/com.termux/files/usr/bin/bash
Please tell if you get error again

Try with #!/usr/bin/env bash in the shebang line.
Termux-exec allows you to execute scripts with shebangs for traditional Unix file structures. So shebangs like #!/bin/sh and #!/usr/bin/env python should be able to run without termux-fix-shebang.
From https://wiki.termux.com/wiki/Termux-exec

According to doc:
Why do I keep getting a '/bin/sh bad interpreter' error?
This error is thrown due to access script interpreter at nonexistent
location.
Termux does not have common directories like /bin, /sbin, /usr/bin at
their standard place. There is an exception for certain devices where
/bin is a symbolic link to /system/bin, but that does not make a
difference.
Interpreters should be accessed at this directory only:
/data/data/com.termux/files/usr/bin
There are three ways to fix this:
Install termux-exec by using pkg install termux-exec. It won’t affect the current session, but after a restart should work without
any setup. Not needed if your Termux is up to date. If still not
working, try the next workaround.
Use command termux-fix-shebang to fix the shebang line of specified file.
Use termux-chroot from package proot to setup a chroot environment mimicking a normal Linux file system in Termux.
termux-fix-shebang my_script.py of second method work for me, which it modify the shebang(first line of my_script.py) from #!/usr/bin/env python to #!/data/data/com.termux/files/usr/bin/env python. Since /usr/bin/ is not exist in Android, that's why it throws the error /usr/bin/env: bad interpreter: No such file or directory. The other solution is run with python my_script.py, neither of my_script.py nor ./my_script.py.
In my test, termux-exec of the first method only work if I added correct shebang in main script(child OR child of child script no need) and ran command export LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so.
And for the issue of this question, error shows /usr/bin/env in the middle with /data/data/com.termux/files/usr/bin/wp even though the shebang of script #!/data/data/com.termux/files/usr/bin/bash looks ok, it means that wp command (located at /data/data/com.termux/files/usr/bin/wp) used inside the script contains shebang #!/usr/bin/env wp and should modify it to #!/data/data/com.termux/files/usr/bin/env wp too. termux-exec of first method should fix this specific case too(already has correct shebang in main script).

Related

How Can I Execute A Python Script By Just Typing The Script's Name?

I have a python script that I want to execute from the terminal, but I don't want to use the command pythonscriptName.py, instead, I'd like to just type scriptName. Is that possible? If it is, how?
I had a look in here and here, but it doesn't work (probably because I'm on a different os).
I'm using python 2.7.9 on osx Yosemite (10.10.3).
Put this as the first line in your Python script:
#!/usr/bin/python
(or wherever your Python interpreter lives).
Then give the script the executable bit:
chmod +x scriptName.py
Now you should be able to execute it like ./scriptName.py. You can then put a symlink without the .py extension somewhere in your path.

Python script.py once saved now won't load as before

I have just started looking & learning Python (on Ubuntu 14.04) using the website: http://learnpythonthehardway.org/book/ and http://www.codecademy.com/
Yesterday, I worked for an hour on a few scripts namely 1-4 and named them as ex1.py etc and they executed fine. Today, I have come back to carry on with a few more exercises and tested my first exercises only to find now I get "SyntaxError: invalid syntax" when attempting "python ex1.py" with or without .py I have tried "#!/usr/bin/python" in any script header also. The path/Dir I have been using to test my Python scripts in is simply 'Python' within my Home Dir. I checked the actual file permissions but that appears to make no difference.
I am not too sure if it's an OS setup issue; Python issue; or simply me. Python seems great, so any ideas on what I'm doing wrong? What has changed since yesterday to my python.py script files?
The problem is that you are in the Python interpreter, and not the Linux terminal. This is indicated both by the error messages you saw and by the >>> prompt.
Exit the interpreter by holding down control and pressing the D key. You will then be back in the Linux terminal and running a script will work the way you expect it to.

How do I run my Python program that I wrote?

I am trying to run my celcius.py file but I don't know what to type in the command line...
When I type Python celcius.py it does not work:
I get the following message:
>>> python celcius.py
File "<stdin>", line 1
python celcius.py
^
SyntaxError: invalid syntax
>>>
When I open it the program with the Python IDLE GUI it runs the program and closes the program before I can see it. I read somewhere that it won't close if you run it from the command line.
You need to type "python celsius.py" in the windows command prompt, rather than the Python command prompt; this only works straight away if the Python directory is in your PATH. It probably isn't, so you need to use this instead: C:\Python27\python.exe celsius.py.
Because celsius for you is in the same folder as python, you can do this as well:
CD C:\Python27
python.exe celsius.py
In general, change the directory (CD) to where your file is stored, then run C:\Python27\python.exe <filename>
Double-clicking is generally easier in Windows, though, assuming it is set up to do that (it normally is unless you change it back)
There are a few ways of doing this.
WAY 1
step one: Open command prompt (go to start and type in "cmd") *NOTE: do NOT open python. if you see ">>>" in your command prompt window you opened python. This is bad.
step two: type in this: python "path\to\file\celcius.py" replacing path\to\file with the path (starting with the name of the folder that you're computer user is named. So for my computer that would be ben. So let's say my celcius.py is located on the desktop I would run python "Desktop\celcius.py" and hit <.enter.>. It looks like you have celcius.py in your python folder. Don't put it there. that's the system files for python itself. move it to your desktop or your documents folder. By the way, if you have truble using this, make sure you're system is set up to execute the python command. Go here for reference.
WAY 2
assuming you have python associated with the .py file in explorer, you can find the file and double-click on it.
WAY 3
open IDLE (you can usually find it in your list of programs in start). Open the python file through IDLE. This will show you the source code for your program. hit <.F5.>. F5 will execute the program from within the the IDLE shell.
You don't need to do this, just open the command prompt and type:
python path/to/your/file.py
Just make sure that python command is set in your environment PATH, check this

How to create a project with Bitnami DjangoStack?

I just installed the Bitnami DjangoStack and want to know how to create a new project in Windows.
I tried opening the python.exe (similar to command prompt) and tried typing in:
django-admin.py startproject testproject
which is what all the articles seem to say to start with.
I am getting an invalid syntax error. I'm assuming I'm missing something very basic?
Thanks!
You need to run django-admin.py from the command prompt.
The Python interactive interpreter (what you get when you open up python.exe) is for typing in Python code and running it line by line. If you want to run Python code that is in a file, you need to run it from command prompt.
Note that if that doesn't work, you might need to put python before it, and you also might need no specify the full path (usually something like python C:/Python27/Scripts/django-admin.py, assuming you're on Python 2.7.)

Compiling node.js on Cygwin

I'm trying to build node.js on my Windows XP box (Yes, it IS painful, thanks.) using Cygwin following Ryans instructions here.
Sadly calling "./configure" from the node source directory barfs up this:
$ ./configure
/home/LWE/sources/node.js/wscript: error: Traceback (most recent call last):
File "/home/LWE/sources/node.js/tools/wafadmin/Utils.py", line 274, in load_module
exec(compile(code, file_path, 'exec'), module.__dict__)
File "/home/LWE/sources/node.js/wscript", line 12, in <module>
import js2c
File "/home/LWE/sources/node.js/tools/js2c.py", line 35, in <module>
import jsmin
File "/home/LWE/sources/node.js/tools/jsmin.py", line 1
../deps/v8/tools/jsmin.py
^
SyntaxError: invalid syntax
I'm absolutely not into Python so I'm having a hard time figuring this out. Am I missing some dependency or what?
I'd expect that there is some simple little configuration switch that I have to turn, to make this work. I just don't know where/what/why/...
I compiled node.js on my Mac before from the very same sources and that worked like a charm. And I also can't imagine that the build script from the node repository itself is broken.
PS: It's a totally fresh and up to date Cygwin installation with Python 2.6.5.
I also had a problem getting nodejs to compile using cygwin - also a Python issue. I eventually found a reference to having to rebase the cygwin DLL links to make everything work. Of course I couldn't find my original source for help. But I remembered enough to find similar help.
So from http://avalanche123.tumblr.com/post/855374337/nodejs-mongodb-tinyurl
I remembered that you can stop all cygwin processes, run ash (a minimal shell) that is typically found at C:\cygwin\bin\ash.exe and then, in this shell, run "/usr/bin/rebaseall"
Once I had run the rebaseall command I could, using the normal cygwin shell, successfully run the ./configure script for the nodejs source and proceed to "make" and "make install" nodejs.
This is old, but for anyone referencing this page: jsmin.py is a symbolic link. If you are using Git from msysGit in Cygwin, symbolic links will not be created properly. The Git client that comes with Cygwin deals with these pretty decently most of the time, however every now and then it barfs. If you bring up jsmin.py in an editor, you will see it actually contains the path to the file it is supposed to be linking to. To fix this and move on to compiling:
# from the node.js source directory, run:
% cd tools
% ln -fs `cat jsmin.py`
This will recreate the symlink pointing to the proper location. From here, re-run ./configure and you are all set.
A full set of build instructions is available at Github.
I had no problems using Ryan's current instructions -- until I tried install ing NPM as well, and then I got no output. If you are using cygwin and installing node.js, be sure to use the "works" tag when you git the file, instead of a specific version number. Otherwise, no output/non working npm.
Now to figure out getting mongo setup properly...