Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/usr/bin/env: ‘python’: No such file or directory - update scripts to python3 #792

Closed
ghost opened this issue Apr 21, 2020 · 26 comments
Closed
Labels

Comments

@ghost
Copy link

ghost commented Apr 21, 2020

O/S specifications:

lsb_release -a

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 19.10
Release:        19.10
Codename:       eoan

uname -a

Linux dn00 5.3.0-46-generic #38-Ubuntu SMP Fri Mar 27 17:37:05 UTC 2020 \
x86_64 x86_64 x86_64 GNU/Linux

python --version

Python 3.7.5

php --version

PHP 7.3.11-0ubuntu0.19.10.4 (cli) (built: Apr  8 2020 18:58:29) ( NTS )

Instructions for installation:

https://tagui.readthedocs.io/en/latest/setup.html

ls /usr/local/bin/ | grep tag

tagui

tagui /home/qih/tagui/flows/samples/1_google.tag

PHP Warning:  file_get_contents(tagui_chrome.in): failed to open stream: No such file or directory in /home/qih/tagui/src/tagui_chrome.php on line 34
/usr/bin/env: ‘python’: No such file or directory

On execution of the above 'tagui command, the Chrome Browser briefly renders an instance of the UI then crashes, with no further error message at STDOUT.

I 'rm -rf' the ~/tagui and redid the process exactly same, with the same result.

@kensoh
Copy link
Member

kensoh commented Apr 21, 2020

Hi @QuiParses are you running TagUI with the qih user?

Above error message No such file or directory in /home/qih/tagui/src/tagui_chrome.php is suggesting that for some reason TagUI does not have permission to create that file on your computer. Below more details, just simple writing and reading from a dummy file.

The few lines of code in tagui/src/tagui_chrome.php that trigger the error message -

// initialise interface in-file before starting main loop
file_put_contents('tagui_chrome.in','');

// main loop to scan inputs from automation flow
echo "[tagui] START  - listening for inputs\n\n"; while (true) {

// scan input from run-time interface in-file
$tagui_intent = trim(file_get_contents('tagui_chrome.in'));

@ghost
Copy link
Author

ghost commented Apr 21, 2020 via email

@kensoh
Copy link
Member

kensoh commented Apr 21, 2020

For the error message /usr/bin/env: ‘python’: No such file or directory, TagUI will run the command python if it detects that Python is used in your automation. From above 1_google.tag it does not use Python, but not sure why Python is called. You can check 2 things, try typing python from the same user terminal that you type tagui command to see if Python is launched. Next is check whether there is a file tagui/src/tagui_py/tagui_py.in file. There shouldn't be this file there if Python is not required in the automation script.

@kensoh
Copy link
Member

kensoh commented Apr 21, 2020

For user permissions, try doing a chmod -R 777 /home/qih/tagui to make all files and directories full permissions, and try running again to see if it works. If it works, that means something wrong with the permissions assigned to some of the files or folders there.

@kensoh kensoh added the query label Apr 21, 2020
@ghost
Copy link
Author

ghost commented Apr 21, 2020 via email

@kensoh
Copy link
Member

kensoh commented Apr 21, 2020

try this -

cd /home/qih/tagui/src
./tagui ../flows/samples/1_google.tag -n

If it works, it could be the way you do the symbolic link is not working and TagUI isn't launched from the correct working directory. If it doesn't work, it could be some strange behaviour on Ubuntu on running scripts and their working directory, which isn't discovered before.

@kensoh kensoh changed the title /usr/bin/env: ‘python’: No such file or directory /usr/bin/env: ‘python’: No such file or directory - pending replication and checks Apr 21, 2020
@ghost
Copy link
Author

ghost commented Apr 21, 2020 via email

@kensoh kensoh changed the title /usr/bin/env: ‘python’: No such file or directory - pending replication and checks /usr/bin/env: ‘python’: No such file or directory - pending replication checks Apr 21, 2020
@kensoh
Copy link
Member

kensoh commented Apr 21, 2020

If python command is not available on your system, try modifying tagui\src\tagui and change the line

python -u tagui_py/tagui_py.py

to

python3 -u tagui_py/tagui_py.py

But don't think this is the cause of the problem, because the Google sample does not need Python at all, so it shouldn't even try to launch python command.

@ghost
Copy link
Author

ghost commented Apr 21, 2020 via email

@ghost
Copy link
Author

ghost commented Apr 21, 2020 via email

@kensoh
Copy link
Member

kensoh commented Apr 21, 2020

Try running this -

cd /home/qih/tagui/src
./end_processes

That command kills all TagUI-related dead processes. It could be for some reason, there is some dead TagUI processes that is messing up when you try to run tagui on the sample.

@ghost
Copy link
Author

ghost commented Apr 21, 2020 via email

@ghost
Copy link
Author

ghost commented Apr 21, 2020

Deleted tagui*; reboot, cp & unzip Tagui*.zip
Modified ~/tagui/src/tagui

python -u tagui_py/tagui_py.py >> tagui_py/tagui_py.log 2>&1 &
# python3 -u tagui_py/tagui_py.py >> tagui_py/tagui_py.log 2>&1 &

Execute again

$ cd /home/qih/tagui/src
$ ./tagui ../flows/samples/1_google.tag -n
/usr/bin/env: ‘python’: No such file or directory

Execute the command directly

$ python3 -u tagui_py/tagui_py.py >> tagui_py/tagui_py.log 2>&1 &
[2] 7040

End Processes

$ ./end_processes
$ ./tagui ../flows/samples/1_google.tag -n
/usr/bin/env: ‘python’: No such file or directory

I also went through the ~/tagui/flow/samples* 1 by 1, to verify that there was no Python call hidden in there, which of course there was not. It is acting as if it does not see Python3?

@ghost
Copy link
Author

ghost commented Apr 21, 2020

Progress

Modify ~/tagui/src/tagui

Chrome string

# chrome_command="google-chrome"
chrome_command="google-chrome-stable"

Python string

# python -u tagui_py/tagui_py.py >> tagui_py/tagui_py.log 2>&1 &
/usr/bin/python3 -u tagui_py/tagui_py.py >> tagui_py/tagui_py.log 2>&1 &

Execute

$ ./tagui ../flows/samples/1_google.tag  // Removed '-n' switch
PHP Warning:  file_get_contents(tagui_chrome.in): failed to open stream: 
No such file or directory in /home/qih/tagui/src/tagui_chrome.php on line 34
/usr/bin/env: ‘python’: No such file or directory

@kensoh
Copy link
Member

kensoh commented Apr 21, 2020

Hi @QuiParses thanks for all the troubleshooting details and logs!

I've looked through your details carefully, and I'm afraid I have no idea why above bizarre error is happening. Since you have already changed the Python command to python3 and you still get the python not found error.

I'm assuming that you are running a real Linux and not a Linux shell within Windows. If so, can you try look for another computer with Linux that you can try to see if the same error happens? Maybe your personal laptop or borrow your colleague or friend laptop.

If the other computer you cannot replicate the error, then compare the OS settings between the 2 computers to figure out what could be the cause of the problem. I'm recommending you try another laptop as you have already traced very deeply and looking further in this track is likely to waste your time without any new clues.

@kensoh
Copy link
Member

kensoh commented Apr 21, 2020

Also, I have not received any report of such an error by any TagUI user (there are over 1k users using it on Linux), so there isn't more data points from my experience what could have caused this bizarre error.

Since the TagUI source code is the same, but error is only happening on your laptop, I suspect that the more likely reason is some unique OS or environment configuration that is the root cause.

@ghost
Copy link
Author

ghost commented Apr 22, 2020

Thanks for the update. I am using Kubuntu on a Desktop Machine but with a 'standard' install. I even went as far as to disable ~/.bash_aliases in case one of the Python aliases was causing an issue.

I am planning to wipe this HDD and reinstall anyway, plus I will configure Tagui on one of my Raspberry Pi (Which run Python 2.7 by default) as an extra test. Thanks for all your help & patience.

@kensoh
Copy link
Member

kensoh commented Apr 22, 2020

You're welcome @QuiParses, hope there is some good results soon!

I'll close this issue for the time being, pending further inputs from your investigation.

@kensoh kensoh closed this as completed Apr 22, 2020
@ghost
Copy link
Author

ghost commented Apr 25, 2020

Follow up to Issue: /usr/bin/env: 'python': No such file or directory.

Drastic Actions:

  • Say 10 'Hail Marys'
  • Backup, overwrite sectors & reformat HDD
  • Install Lubuntu 20.04
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04 LTS
Release:        20.04
Codename:       focal

Install TagUI

tagui.readthedocs.io/en/latest/setup.html

Install Curl

sudo apt update && sudo apt install curl

Results:

PHP

$ php --version
PHP 7.4.3 (cli) (built: Mar 26 2020 20:24:23) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

Python3

$ python3
Python 3.8.2 (default, Mar 13 2020, 10:14:16) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

Execute TagUI

$ tagui /home/qih/tagui/flows/samples/1_google.tag
/usr/bin/env: ‘python’: No such file or directory

Reoccurence of original issue:

Modify ~/tagui/src/tagui

# Python (2)
# python -u tagui_py/tagui_py.py >> tagui_py/tagui_py.log 2>&1 &
# Python (3)
python3 -u tagui_py/tagui_py.py >> tagui_py/tagui_py.log 2>&1 &

Execute TagUI

$ tagui /home/qih/tagui/flows/samples/1_google.tag
/usr/bin/env: ‘python’: No such file or directory

Logic dictates that there must be other references to 'python' within the codebase that are getting called and causing this error, therefore must find these instances.

Search Tagui codebase

$ cd ~/tagui
$ grep -r /usr/bin/env * | grep python # or
$ grep -r "/usr/bin/env python" *
src/casperjs/tests/clitests/runtests.py:#!/usr/bin/env python
src/casperjs/bin/casperjs:#!/usr/bin/env python
src/slimerjs/slimerjs.py:#!/usr/bin/env python

Remediate

In all 3 files, modify

From: #!/usr/bin/env python
To: #!/usr/bin/env python3

Summary:

If your GNU/Linux system uses Python 3, you must modify all instances
of 'python' to 'python3', after that, it works as per design.

@kensoh kensoh reopened this Apr 25, 2020
@kensoh
Copy link
Member

kensoh commented Apr 25, 2020

Hi @QuiParses that is very detailed and excellent detective work you have there!

Thanks for sharing your findings. Yes the file that breaks this would be this -

src/casperjs/bin/casperjs

TagUI is built on CasperJS, and for the macOS / Linux environments, CasperJS uses Python as entry point to run its code. It's been 3 years since I first wrote the integration with CasperJS, and I've forgot about that when you raise the issue. I'm sorry about that.

Changing the python command to python3 would work on systems where the python command does not exist, and yes you've found the right solution for the problem 👏🏻👏🏻

I'll close the issue for now. And see if there are more cases of such setups, then I'll update documentation or find other ways to remove this friction for such scenarios. Thanks!

@kensoh kensoh closed this as completed Apr 25, 2020
@kensoh kensoh changed the title /usr/bin/env: ‘python’: No such file or directory - pending replication checks /usr/bin/env: ‘python’: No such file or directory - update scripts to use python3 Apr 25, 2020
@kensoh kensoh changed the title /usr/bin/env: ‘python’: No such file or directory - update scripts to use python3 /usr/bin/env: ‘python’: No such file or directory - update scripts to python3 Apr 25, 2020
@kensoh
Copy link
Member

kensoh commented Apr 25, 2020

Adding on, I suspect that instead of changing the files, symbolic linking of below -

/usr/local/bin/python

to the python3 command in your environment may also do the trick as python gets redirected to python3 on your OS. Just a guess, not sure if that works. If it does, would be easier solution.

@ghost
Copy link
Author

ghost commented Apr 25, 2020

Personally, if a newb to GNU/Linux was doing this, perhaps it might be better to be able to modify the TagUI codebase depending on Python ver 2 /3,rather than editing a system wide ENV like 'Python'.

I'll hack up a BASH/DASH script that will detect the OS.Python.ver and modify those Shebang strings. Might take a few days 8-)

@kensoh
Copy link
Member

kensoh commented Apr 26, 2020

Modifying this way is ok, it is not a system-wide environment variable. It is creating a symbolic link for python which does not exist. So it should not cause any impact to break any existing apps.

@pp082
Copy link

pp082 commented Apr 23, 2022

@ghost, @kensoh

Thank you very much I had the same problem with my Mac M1 pro.

Python 3.9 is preinstalled. Making the change from python to python3 solved it.

Search Tagui codebase

$ cd ~/tagui
$ grep -r /usr/bin/env * | grep python # or
$ grep -r "/usr/bin/env python" *
src/casperjs/tests/clitests/runtests.py:#!/usr/bin/env python
src/casperjs/bin/casperjs:#!/usr/bin/env python
src/slimerjs/slimerjs.py:#!/usr/bin/env python

Remediate

In all 3 files, modify

From: #!/usr/bin/env python
To: #!/usr/bin/env python3

@kensoh
Copy link
Member

kensoh commented Apr 23, 2022

Thanks @pp082 for sharing this solution here! 😄

@vivi88888
Copy link

vivi88888 commented May 15, 2023

@kensoh @pp082 @ghost It really helps me a lot!! Because in the later version of OS(It is macOS 13.3.1 (a) now), I find it hard to create a symbolic link for python from python3 after the upgrade of the system protection(the SIP and when trying to edit the permission of root file another error occurs like: "/data: Read-only file system") and I suffer it for a whole day!!! THANKS!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants