-1

When I code in Python I use Sublime Text 3.

I've never really understood the #! (shebang) at the top of Python scripts.

One of my scripts wasn't running on Sublime because it had the auto build mode set to python3.9, while my dependencies were installed on Python3.10.

Instead of having to manually switch, I wanted to put a #! at the top of my script so every time it knows which interpreter to use (which version of Python to run). After reading Should I put #! (shebang) in Python scripts, and what form should it take?, it seems to me like the point of a shebang is to run as an executable without having to give the python prefix while typing in the command, kind of like I'm trying to accomplish.

Im trying to run my file via . /path/to/file.py, but it's giving me zsh: permission denied:.

I am running Sublime 3 on macOS and my build system is

{"shell_cmd": ".../Versions/3.10/bin/python3 $file" }

How can I solve the permission issue zsh: permission denied? Is there a Sublime build that incorporates #!?

jonrsharpe
  • 107,083
  • 22
  • 201
  • 376
taylorSeries
  • 133
  • 1
  • 12
  • 2
    the shebang is a hint to your system on how to run your file. you can set it to `#! python3.10` (Assuming it's on your PATH). to make the file "runnable" you need to give it run permissions `chmod u+x /path/to/file.py` or just pass it to python directly `python3.10 /path/to/file.py` – Nullman May 18 '22 at 07:59
  • @Nullman its chmod a+x not u+x and really what's a path bruv – taylorSeries May 18 '22 at 08:10
  • 3
    `a+x` gives run permission to EVERYONE, which is not generally considered a good idea (security wise) `u+x` is for the owning user – Nullman May 18 '22 at 08:19
  • ok well IM the only USER on my computer – taylorSeries May 18 '22 at 08:21
  • EVERYONE is ME. and if you can get in, SETTING file PERMISSIONS ISNT GOING TO DO ANYTHING because they were smart enough to get in! – taylorSeries May 18 '22 at 08:22
  • 2
    @PrestigeDev the point they're trying to make is that it's good practice to minimize permissions and other security threat vectors, *even* if you're the only user of a system. But, you're going to do what you're going to do, even if the change is typing a `u` instead of an `a`. – MattDMo May 18 '22 at 15:01
  • 2
    If your Python script is flagged as executable, and it has a Shebang that says what Python version to use, why are you trying to use a `shell_cmd` that specifically specifies the Python interpreter to use when your `shell_cmd` could just be `$file` to try and execute the current file? – OdatNurd May 18 '22 at 16:30
  • @OdatNurd - that's a great point lol – taylorSeries May 18 '22 at 23:06

0 Answers0