A. L
A. L

Reputation: 12649

Multiple shebangs to work for different OS

Is there a way I can have multiple shebangs?

So I can call #!/usr/bin/env python3 on Ubuntu, but MacOS doesn't seem to have an equivalent, and I would like to call #!/usr/bin/python3 instead on it.

So is it possible to do something like:

#!/usr/bin/env python3
#!/usr/bin/python3

Upvotes: 8

Views: 5183

Answers (1)

codeforester
codeforester

Reputation: 42999

We can't have multiple shebang lines - there can only be one and it should always be the first line.

If you need to support multiple versions of Python based on OS, it is best to write a small shell wrapper that invokes your python script with the right interpreter, probably with an exec.

macOS does have /usr/bin/env.


See this post:

Upvotes: 13

Related Questions