0

I wrote some code on my laptop and now I am trying to run this code. But it give me the output : Permission denied Usually that should only happen if a different user would try to access it. But I am the user who wrote it and is trying to run it now. I feel like this will be an easy issue to resolve but any help would be nice! Thanks.

I wrote and saved the code in IDLE python. Once I finished I tried running it in my Terminal (I have the macOS Mojave Version 10.14.5) but then I ran into the issue.

Evandros-MBP:~ evandro$ ./Desktop/FunCodes/pwd.py

This is how I tried to call up the code. I don't see any issues here.

khelwood
  • 55,782
  • 14
  • 81
  • 108
Evandro
  • 13
  • 1

2 Answers2

0

Instead of calling the script with

./Desktop/FunCodes/pwd.py

try using

python ./Desktop/FunCodes/pwd.py

or also

python3 ./Desktop/FunCodes/pwd.py

if you want to execute it with python3 instead of python2.

Explanation

When you write ./some-file in the terminal (without writing python before the file path), the terminal executes it as a bash file (no matter if the file has a .sh extension or not). Of course, since your file is a python file, this will fail. But even before it fails, since your python file has no permission to be executed, permission will be denied and bash won't even start.

jfaccioni
  • 7,099
  • 1
  • 9
  • 25
0

On creation, the file only has read and write permissions. Add a shebang pointing to the Python interpreter on the script's first line, for example #!/usr/bin/env python. Also, your script is not marked as executable, in order to do that you need to use:

chmod +x pwd.py

Otherwise you will only be able to run it with Python, with

python pwd.py
Pedro Henrique
  • 601
  • 6
  • 17