That's a great question! In Linux (the system running in this VM), every file has specific "rules" about who can do what with it. These are called Permissions.
There are three main types of permissions:
- Read (r): The ability to open and look at the contents of the file.
- Write (w): The ability to modify or delete the file.
- Execute (x): The ability to run the file as a program or script.
Why did you see an error?
When you created user_info.py, it was created as a text file. By default, text files only have Read and Write permissions.
When you tried to run it by typing just the path /home/labex/project/py.py, the system looked for that Execute (x) permission. Since it wasn't there, the system blocked it and said "Permission denied."
Two ways to run code:
-
Way 1 (The "Interpreter" way):
python ~/project/user_info.pyYou are running the
pythonprogram (which already has execute permissions) and asking it to read your file. This is the standard way to run Python scripts. -
Way 2 (The "Executable" way):
If you wanted to run the file directly like a program (e.g.,./user_info.py), you would first have to manually grant it execute permissions using a command calledchmod:chmod +x ~/project/user_info.py # This adds the 'eXecute' permission
In this lab, you don't need to change permissions; just using the python command is the best way to go! Would you like to try running the script with the python command now?