0

I have a python 3 program in file foo the file has execution permissions, and the first line of the script is

#!/usr/bin/python3

When I run the file from python directly, i.e:

/usr/bin/python3 foo 3 boo

Everything runs perfectly well, but when I try to run the program by calling the file name I get:

foo 3 boo
foo: Command not found.

Even when specifying the relative or full path to the script I get the same response.

./foo 3 boo
./foo: Command not found.
/full/path/to/the/file/foo 3 boo
/full/path/to/the/file/foo: Command not found.

Some more info that was requested:

head -2 foo
#!/usr/bin/python3
which python3
/usr/bin/python3

Working from tcsh, where is the problem?

I'm working on a remote university computer through ssh, could it be the case that the sysadmins somehow prevent this?

asked Oct 29, 2018 at 17:05
9
  • Have you made your script executable? Commented Oct 29, 2018 at 17:07
  • @Anton, yes I did Commented Oct 29, 2018 at 17:08
  • @Anton read carefully the question. He explicitly said it have. Commented Oct 29, 2018 at 17:08
  • @RaoslawSzamszur Yep, my bad. And the answers below are correct Commented Oct 29, 2018 at 17:09
  • @SIMEL, can you do show the head -2 foo & which python output from terminal? Commented Oct 29, 2018 at 17:12

4 Answers 4

3

You need to specify the absolute path of the script. Try

./foo 3 boo

while in the same directory as the script. Otherwise, the shell will only look in your PATH for something named foo, which doesn't exist.

answered Oct 29, 2018 at 17:07
Sign up to request clarification or add additional context in comments.

1 Comment

I get the same response, even when stating the full path to the script, I get the same response.
0

You must give the path to the file

./foo

If you just call "foo", the shell will look in the environment variable $PATH the folder that contains the "foo" binary, and he will not find it ...

answered Oct 29, 2018 at 17:10

Comments

0

I'm using python3, just an example illustration..

Just a test script ..

$ cat test.py
#!/python/v3.6.1/bin/python3
import os
print(os.system("ls"))
$ which python3
/python/v3.6.1/bin/python3

Permission to make it executable.. i'm have doubt if the script foo is executable in your case..

$ chmod +x test.py

Test Run..

$ ./test.py
a.py Backup File_Write_Method NWK-old Python_aritsTest Python_Ftp Python_Mail Python_Primer test.py
argpass BASH Network_DeOps Python-3.6.3 Python_Dump Python_FTP Python_Panda readme_python tmp
awk.sh dnspython nslookup Python-3.6.3.tar.xz Python_excep Python_ldap Python_Parsers Regular_Expr tt.csv
0

It might be shell problem as i reproduced the tcsh shell & it fails to run..

$ tcsh
$ ./test
./test: Command not found.

but it runs , when i run it like below..

tcsh -c ./test.py
answered Oct 29, 2018 at 17:18

1 Comment

@wpercy, thats weird :)
0

Assuming your script is executable and you have python3 in /usr/bin/python3. I think you are trying to run your script from a partition mounted with the noexec argument to check if it is the problem you should run:

mount | grep <partition> | grep noexec

If I'm right you can just mount the partition with the exec option or move your script elsewhere.

answered Oct 29, 2018 at 17:35

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.