I tried to execute my python file using ./mypy.py
on freebsd. I have used chmod +x
, and I have added the shebang #!/usr/local/bin python
(my python is under /usr/local/bin) on the top of the file. However, I kept getting permission denied. I have tried using sudo
and even execute the file as root, but the error is still there. What should I do to fix this?
Asked
Active
Viewed 100 times
0

高造擎
- 71
- 5
-
1you mean `#!/usr/local/bin/python` right? as you wrote the shebang will try to execute "bin' directory. – Jean-François Fabre May 14 '23 at 13:46
-
... agree with above, but, IIRC, the `pythonxy` package (whatever version) doesn't add the link `python` to `pythonX.Y` (post-install). You have to make it yourself. So, if you didn't make the link, your shebang has to be `#!/usr/local/bin/pythonX.Y`. – Valery S. May 14 '23 at 13:57
-
You guys are my heros. I wonder why all the links I have read suggest #!/usr/local/bin python. For example: https://stackoverflow.com/questions/4993621/how-to-run-python-script-without-typing-python. Is it because they are using linux? – 高造擎 May 14 '23 at 14:13
-
I do not see any references to `/usr/local/bin python` in the question you linked. There are plenty of uses of `/usr/bin/env python`, but that's something entirely different - `env` is a program, not a directory. – jasonharper May 14 '23 at 15:34
-
1See the meta ports *lang/python* and *lang/python3*. They will create the links for you. – Vladimir Botka May 14 '23 at 16:31
1 Answers
0
To execute, interpreter languages require both execute and read permissions.
Look at this example below:
$ sudo cat test.py
#!/usr/local/bin/python3
print("test")
$ ls -l test.py
--wx--x--x 1 spmzt spmzt 41 May 28 21:00 test.py
$ ./test.py
/usr/local/bin/python3: can't open file '/usr/home/spmzt/./test.py': [Errno 13] Permission denied
$ chmod +r test.py
$ ./test.py
test

spmzt
- 86
- 7