Haha, still not getting the hang of this, I am afraid. I have written a script:

#!/usr/bin/env python
print ("Hello, world!")
name = input("What is your name? ")
print ("Hello, " + name + "!")

I have saved it as hello.py. And I try to make it executable in terminal:

chmod a+x hello.py

That, however, leads to following error message:
chmod: cannot access `hello.py': No such file or directory
Why is that?

Typically in *nix, when you open up a console it opens in your home directory. Bearing this in mind, when you're using the chmod command, are you actually in the directory that you saved hello.py in? The error message appears to say that the file cannot be found, so it sounds to me like you're not in the correct directory!

If you are in the wrong directory, try using:

chmod a+x /path/toscript/hello.py

Obviously substituting '/path/toscript/hello.py' with the actual path to the file.
e.g.

chmod a+x /home/username/Documents/pyscripts/hello.py

Otherwise use cd to move into the appropriate directory before trying the chmod command.
e.g.
Open up a terminal and type:

cd /path/toscript 
chmod a+x hello.py

Again, substitute /path/toscript/ with the actual path to your python script.

The only other thing I can suggest is perhaps you need to explicitly qualify that the file is in the current directory by using './' at the start of the filename in the call to chmod:
e.g.

cd /path/toscript
chmod a+x ./hello.py

Also note: After doing the 'cd' and before doing the 'chmod' in the two examples above, you might also want to consider using the 'ls' command to make sure that your .py file is definitely there!
e.g.

ls -l hello.py

If the file is there, then it will be listed by the 'ls' command, but if it says that the file cannot be found, then you must've saved it elsewhere or deleted it or something!

Failing all of that, if your python script is owned by root you might have to use 'su' or 'sudo' (depending on your distro) in order to have sufficient privileges to be able alter the file's permissions via chmod.
e.g.

sudo chmod a+x /path/toscript/hello.py

This step will probably ask you for the password for root access. Once you've entered the password correctly the chmod should change the file permissions for you.

Other than that, I'm out of ideas. There's really not a lot more that it could be. Hopefully something in there helped, but if nothing worked, please post again with more details.
i.e. which version/distro of *nix you're running, the exact location and file-name you've saved your python script to etc etc.

Cheers for now,
Jas.

You can just do stuff in home directory if you dont really care much about clutter. But i recommend making a directory called python_scripts.

mkdir python_scripts
cd python_scripts
gedit pythonscript1.py
## after coding your scripts save fie, close gedit, then:
chmod a+x pythonscript1.py
./pythonscript1 ##<<< thats how you run it

Make your life easier by using the IDLE editor to write, save and run your programs from. IDLE usually comes with the Python installation or you can get it from the repository.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.