/tmp/geany_run_script_T62ZV1.sh: 7: python: not found

I have gone from Ubuntu Mate 18.04 to 20.04

Need some help getting python working. :slight_smile:

My scripts are readable and executable.

#! /usr/bin/python3
# hello.py
 
# Save the string "Hello " to a variable 
# Space is added at the end for when we join our input
# 

hello_text = "Hello "
 
# Get user input
name = input("Enter your name: ")
print() # This prints a newline.
 
# Join our strings using the '+' operator which will
# concatenate two strings together into a new variable
message = hello_text + name
 
# Display the joined message to our user
print(message)

When I run this script from Geany, I get this.

/tmp/geany_run_script_T62ZV1.sh: 7: python: not found

It runs fine from the command line.

andy@7 ~/Python> python3 hello.py
Enter your name: andy

Hello andy

python3 -V
Python 3.10.6

In Ubuntu, python is no longer installed by default since 20.04. Note that python and python3 are different and Geany is looking for the former. python refers to python2.7, which reached end of life some time ago.

It seems like Geany is not respecting your shebang, which is pretty bad form if you ask me. I’m not familiar with Geany, but it probably has a setting somewhere to make it use python3 instead. If not, you can also install the python-is-python3 package, which will symlink python3 to python.

Edit: Actually, there is a space in your shebang. It shouldn’t be there. Try removing it.

1 Like

Thanks for your reply.

I got geany to run it by changing the build command to

python3 "%f"

Does

“%f”

work?
I wonder of it just runs your script as is.

Sorry, I meant it is an execute command.

%f is a replaceable parameter.

In Unix-like systems when you correctly set a shebang and enable the executable bit of the file you can run the script directly. You do not need to invoke the python3 interpreter explicitly:

~/tmp/python$ cat >script.py
#!/usr/bin/python3
print("Hello!")
~/tmp/python$ chmod a+x script.py
~/tmp/python$ ./script.py
Hello!

That is the reason why Barry asked about testing "%f".
If Geany does not set the executable bit for you, you can do it manually.

1 Like

I can run scripts without the
./

script.py

You can do that if you have the current directory .[1] in your PATH environment variable but this is a security risk! Imagine someone plants a malware called ls into your /tmp. You then execute cd /tmp ; ls


  1. or even just an empty item created by leading, trailing or doubled colon : ↩︎

I am the only one with physical access to my computer.

How could someone plant anything on my computer?

If attacks were limited to physical access then we would be much safer :slight_smile:


It could be planted by a malware in a form of a trojan horse (for example a code hidden in a copy+paste from web, or software downloaded from a good-looking URL). It can come through a vulnerability or social engineering…

There are many ways :slight_smile:

1 Like

I understand what you are saying.

But how does my path pose a risk?

If you have added “.” to your path then you are risk of picking a program from your current directory.

The least bad out come is that you get a surprise because a local file shadows a system command. Favority surprise file name is “test” that is used by lots of scripts.
test is often created by people to hold a test they are writing.

The worst is that you think you are running a system command but you end up running malware that has been smuggled into your current directory.

For these raason it is consider very bad to add “.” to your path.

I have not added “.” to my path. :slight_smile: