Shebang Line Woes

130 views
Skip to first unread message

Paul Gobble

unread,
Mar 5, 2020, 7:06:11 AM3/5/20
to BBEdit Talk
I'm using BBedit 13.0.5 on Mac Os 10.15.3 as my editor while I try to learn a bit of Python3.  

#!/usr/bin/env python3
print('Hello World')

Baby steps.

I try to execute this from the Run menu item in the #! menu and get

/Users/.../Scripts/python_test-01.py: line 1: #!/usr/bin/env: No such file or directory

Then I try to use the direct path in the shebang line

#!/usr/bin/python3
print('Hello World')

and get a very similar response

/Users.../Scripts/python_test-01.py: line 1: #!/usr/bin/python3: No such file or directory

So I go investigate in the Terminal app and look around.

Emonda:bin paul$ pwd

/usr/local/bin

Emonda:bin paul$ whereis python3

/usr/bin/python3

Emonda:bin paul$ whereis env

/usr/bin/env

Emonda:bin paul$ 


Both env and python3 are right where I said they were in the shebang line, but interpreter can't find them!  

Can anyone help me out here?  What am I missing?

Thanks,
Paul

Rich Siegel

unread,
Mar 5, 2020, 8:23:07 AM3/5/20
to bbe...@googlegroups.com
On 3/4/20 at 11:25 PM, pa...@paulgobble.com (Paul Gobble) wrote:

> I try to execute this from the Run menu item in the #! menu and get
>
> /Users/.../Scripts/python_test-01.py: line 1: #!/usr/bin/env: No such file
> or directory

/usr/bin/python3 is a stub provided by the OS. What happens if you:

python3 --version

?

R.
--
Rich Siegel Bare Bones Software, Inc.
<sie...@barebones.com> <https://www.barebones.com/>

Someday I'll look back on all this and laugh... until they sedate me.

Paul Gobble

unread,
Mar 5, 2020, 12:54:32 PM3/5/20
to BBEdit Talk
Rich,

Here's what I get…

Emonda:bin paul$ python3 --version
Python 3.7.3

Nestor Aguilera

unread,
Mar 5, 2020, 6:40:08 PM3/5/20
to BBEdit Talk


> On 5 Mar 2020, at 14:43, Paul Gobble <pa...@paulgobble.com> wrote:
>
> Rich,
>
> Here's what I get…
>
> Emonda:bin paul$ python3 --version
> Python 3.7.3

And this is what I get in my system:

$ python3 --version
Python 3.8.2
$ which python3
/usr/local/bin/python3
$ whereis python3
$

that is, can't find python3.

There is no file with name starting with python3 in my /usr/bin (but there are several in /usr/local/bin). I guess this depends on the macOS version (I am on 10.14 Mojave).

I installed the python3 version with the pkg in https://www.python.org/downloads which puts /Library/Frameworks/Python.framework/Versions/3.8/bin at the top of the path, but I changed that. Anyway, /usr/local/bin and /usr/bin are at the top om my path.

Hope it helps.

Best,

Nestor

#----------------------------------------------
> --
> This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
> ---
> You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/3e2a4d79-e7c3-456b-bf47-d388d00c7c6d%40googlegroups.com.

Paul Gobble

unread,
Mar 5, 2020, 8:12:19 PM3/5/20
to BBEdit Talk
Nestor,

Thanks for your help, but my results were different.  I set /use/bin/ to be first search path. 

paul@Emonda ~ % PATH=/usr/bin:/usr/local/bin:/bin:/usr/sbin:/sbin
paul@Emonda
~ % env
...
PATH=/usr/bin:/usr/local/bin:/bin:/usr/sbin:/sbin
...


Then I asked the terminal what it knows about the location of Python3


paul@Emonda ~ % python3 --version
Python 3.7.3
paul@Emonda
~ % which python3
/usr/bin/python3
paul@Emonda
~ % whereis python3
/usr/bin/python3


By all accounts, my terminal knows where Python3 is, and it recognizes the location as being the same as the location I put first in env, /use/bin/

Any clues?

> To unsubscribe from this group and stop receiving emails from it, send an email to bbe...@googlegroups.com.

Paul Gobble

unread,
Mar 5, 2020, 10:23:01 PM3/5/20
to BBEdit Talk
I keep banging my head against this problem.  To try something different, I ssh over to my Raspberry Pi.  I check, and its got Python 3 right there in /usr/bin/ . So I use vim to create same script on the Rasperrry Pi, chmod 755, and I see "Hello World" the very first try.  

So to recap, both my PowerBook with macOS 10.15.3 and my Raspberry Pi running Debian GNU/Linux have a version of Python3 installed in their /usr/bin directories.  Both system have /usr/bin in their PATH.  They both have the same two line script and both start with the same Shebang: #!/usr/bin/python3.  The Raspberry Pi works perfect, the Mac can only muster "#!/usr/bin/python3: No such file or directory".

What is different between the two systems? Where should I look? 

Steve deRosier

unread,
Mar 5, 2020, 11:23:02 PM3/5/20
to bbedit
Did you try on your mac the exact same thing you did on Linux? ie
chmod a+x and try to execute it from the command line? My bet is it
works. Personally, I don't think I've ever run a python script via
BBedit, I always use my terminal. In any case, validate you can do it
from the terminal in a "normal" way first, and then I'd suggest
emailing support.

- Steve
> --
> This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
> ---
> You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/f3a60234-2b25-44bc-8200-58c528dc8bca%40googlegroups.com.

Jean-Christophe Helary

unread,
Mar 5, 2020, 11:43:18 PM3/5/20
to bbe...@googlegroups.com
First, it works on my system.

================================================================================
Mar 6, 2020 13:35:25
/untitled text 2
--------------------------------------------------------------------------------
Hello World


I can't say for sure that BBEdit respected the first line, but I don't have any issue with the output.

Even when I save the file I get the same:

================================================================================
Mar 6, 2020 13:40:10
~/Documents/Code/test/python_test-01.py
--------------------------------------------------------------------------------
Hello World


I can't tell you more, but if it's a path issue, reinstalling python3 with a reasonable package manager (homebrew ?) could help fixing issues.

Jean-Christophe
> --
> This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
> ---
> You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/f3a60234-2b25-44bc-8200-58c528dc8bca%40googlegroups.com.

Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune


Jan Erik Moström

unread,
Mar 6, 2020, 2:08:06 AM3/6/20
to BBEdit Talk
On 6 Mar 2020, at 3:25, Paul Gobble wrote:

> What is different between the two systems? Where should I look?

Wild suggestion (probably has nothing to do with your problem), are you
running the same shell depending on how you launch your script, i.e. is
the PATH the same for all instances (although since you use the absolute
search path it shouldn't matter).

FWIW on my machine

~ > which python3
/usr/bin/python3
~ > python3
Python 3.7.3 (default, Dec 13 2019, 19:58:14)
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D
~ > /usr/bin/python3
Python 3.7.3 (default, Dec 13 2019, 19:58:14)
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D
~ > vi test
~ > chmod u+x test
~ > ./test
Hello world

Program in test

#!/usr/bin/python3
print("Hello world\n")

= jem

Paul Gobble

unread,
Mar 6, 2020, 6:53:43 AM3/6/20
to BBEdit Talk
Steve,

I took BBEdit out of the testing earlier this evening. I've been doing all my editing with vim and attempting to run the script from the command line.  I've made the two test cases as similar as possible. Both env and Pyton3 reside in /usr/bin on both systems.  The PATH contains /usr/bin in both systems.  the scripts on both systems have the same chmod 755 permissions.  The Raspberry Pi runs like you'd expect, the Mac just won't comprehend or acknowledge the Shebang line.

I'm at a loss.
> To unsubscribe from this group and stop receiving emails from it, send an email to bbe...@googlegroups.com.

Jean-Christophe Helary

unread,
Mar 6, 2020, 7:08:49 AM3/6/20
to bbe...@googlegroups.com


> On Mar 6, 2020, at 13:45, Paul Gobble <pa...@paulgobble.com> wrote:
>
> Steve,
>
> I took BBEdit out of the testing earlier this evening. I've been doing all my editing with vim and attempting to run the script from the command line. I've made the two test cases as similar as possible. Both env and Pyton3 reside in /usr/bin on both systems. The PATH contains /usr/bin in both systems. the scripts on both systems have the same chmod 755 permissions. The Raspberry Pi runs like you'd expect, the Mac just won't comprehend or acknowledge the Shebang line.
>
> I'm at a loss.

How did you install python3 ?

Jean-Christophe

Sam Hathaway

unread,
Mar 6, 2020, 9:58:23 AM3/6/20
to BBEdit Talk

Paul,

I take it you’re on macOS 10.15 Catalina, since /usr/bin/python3 exists.

What do you get if you run this?

ls -le@ /Users/.../Scripts/python_test-01.py

My suspicion is that macOS might have quarantined your script. (I ran into this once or twice after migrating my data to a fresh 10.15 install but I don’t recall the exact error message.)

If you see com.apple.quarantine in that output, you can run this to remove the quarantine flag:

xattr -d com.apple.quarantine /Users/.../Scripts/python_test-01.py

If that isn’t it, I’d be curious to see if you can run the script by passing it to the interpreter like this:

/usr/bin/python3 /Users/.../Scripts/python_test-01.py

Hope this helps.
-sam

--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/e1aaa223-81f1-4c3d-96e6-dd0872e7d420%40googlegroups.com.

Steve deRosier

unread,
Mar 6, 2020, 10:13:40 AM3/6/20
to bbedit
On Fri, Mar 6, 2020 at 3:53 AM Paul Gobble <pa...@paulgobble.com> wrote:
>
> Steve,
>
> I took BBEdit out of the testing earlier this evening. I've been doing all my editing with vim and attempting to run the script from the command line. I've made the two test cases as similar as possible. Both env and Pyton3 reside in /usr/bin on both systems. The PATH contains /usr/bin in both systems. the scripts on both systems have the same chmod 755 permissions. The Raspberry Pi runs like you'd expect, the Mac just won't comprehend or acknowledge the Shebang line.
>
> I'm at a loss.
>

Well, first off, you do realize you could still _edit_ with BBEdit and
run from the terminal, right? BBEdit's an editor (a great and
powerful one), not an IDE.

In any case, the fact you can't run it from the command line tells me
there's nothing wrong with BBEdit, there's something wrong with your
python install. Sam's suggestion re: Catalina's quarantine is a good
one. Alternately, you might investigate how you have python installed.
I happen to prefer to utilize the project pyenv to setup my pythons on
both Mac and Linux so I can easily control my versions without
disturbing the system install and without system-dependant hacks:

https://github.com/pyenv/pyenv#readme

Good luck!
- Steve

Paul Gobble

unread,
Mar 6, 2020, 11:16:24 AM3/6/20
to BBEdit Talk
Sam,

Thank you for your input. Yes, my Mac is running MacOS 10.15.3 Catalina. I tried the tests you suggested, see below.

#!/usr/bin/python3
paul@Emonda
Python-RFP-PDF-Scraper % ./python_test-01.py
./python_test-01.py: line 1: #!/usr/bin/python3: No such file or directory
./python_test-01.py: line 2: syntax error near unexpected token `'Hello World''
./python_test-01.py: line 2: `
print('Hello World')'
paul@Emonda Python-RFP-PDF-Scraper % ls -le@ ./python_test-01.py
-rwxr-xr-x@ 1 paul  staff  43 Mar  6 11:01 ./python_test-01.py
        com.apple.lastuseddate#PS       16
        com.apple.macl  72
paul@Emonda Python-RFP-PDF-Scraper % /usr/bin/python3 ./python_test-01.py
Hello World
paul@Emonda Python-RFP-PDF-Scraper %

So, no, nothing about quarantine was reported.  And yes, if I pass it to /usr/bin/python3 on the command line (the exact same path as in the Shebang) it runs fine. 
To unsubscribe from this group and stop receiving emails from it, send an email to bbe...@googlegroups.com.

Paul Gobble

unread,
Mar 6, 2020, 11:21:26 AM3/6/20
to BBEdit Talk
Steve,

Thanks for the tip about pyenv, I’ll take a look at that.

And yes, I understand that BBEdit is just the text editor.  I took it our of the debugging process at this point just to simplify and standardize the environments.  Until I can get this Hello World script to work on both the MacOs and the Raspberry Pi,  I’m working on both systems via ssh from my iPad using the Blink terminal and using the same, simple tools on both. As soon as I get a Hello World from the Mac, I’ll go back to BBEdit.

Sam Hathaway

unread,
Mar 6, 2020, 11:30:30 AM3/6/20
to BBEdit Talk

This is very curious. I don’t recognize the formatting in the error message you’re getting when you run it directly. If the shell couldn’t find the interpreter in the shebang line, it should say something like “bad interpreter” and exit immediately. Instead, whatever is executing this file goes on to the second line of the script and chokes on the print() statement. What shell do you use? (You can use echo $SHELL to find out.)

I wonder if there’s some kind of encoding problem or stray bytes at the beginning of the file. Can you send me the output of this command?

hexdump -C /Users/.../Scripts/python_test-01.py

Thanks!
-sam

To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/bea4b23d-760a-4e96-a121-93051736af6b%40googlegroups.com.

Paul Gobble

unread,
Mar 6, 2020, 11:46:28 AM3/6/20
to BBEdit Talk
Sam,

You might have hit something.  Below is the hexdump from the macOS system (that doesn’t run)

paul@Emonda Python-RFP-PDF-Scraper % hexdump -C ./python_test-01.py 
00000000  ef bb bf 23 21 2f 75 73  72 2f 62 69 6e 2f 70 79  |...#!/usr/bin/py|
00000010  74 68 6f 6e 33 0a 70 72  69 6e 74 28 27 48 65 6c  |thon3.print('Hel|
00000020  6c 6f 20 57 6f 72 6c 64  27 29 0a                 |lo World').|
0000002b

And here is the hexdump for the Raspberry Pi (that does run)

00000000  23 21 2f 75 73 72 2f 62  69 6e 2f 65 6e 76 20 70  |#!/usr/bin/env p|
00000010  79 74 68 6f 6e 33 0a 70  72 69 6e 74 28 27 48 65  |ython3.print('He|
00000020  6c 6c 6f 20 57 6f 72 6c  64 27 29 0a              |llo World').|
0000002c 

I notice the additional “...” as the start of the Shebang on the MacOS hexdump. 

What do you see, and what could that mean?

Thanks!

Sam Hathaway

unread,
Mar 6, 2020, 11:50:23 AM3/6/20
to BBEdit Talk

Yup, you’ve got a byte-order marker there. Try re-saving the file as “Unicode (UTF-8)” rather than “Unicode (UTF-8, with BOM)”. And if BBEdit is saving UTF-8 files with a BOM by default, you’ll probably want to change the “Default text encoding for new documents” in Preferences > Text Encodings. (There’s no good reason to have a BOM for UTF-8.)

Hope this helps!
-sam

To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/2aeaf792-3c3b-4e01-8503-6b4982bfaea1%40googlegroups.com.

Rich Siegel

unread,
Mar 6, 2020, 12:38:39 PM3/6/20
to 'Dan White' via BBEdit Talk


> On Mar 6, 2020, at 11:46 AM, Paul Gobble <pa...@paulgobble.com> wrote:
>
> I notice the additional “...” as the start of the Shebang on the MacOS hexdump.
>
> What do you see, and what could that mean?
>

It means that you saved your file as Unicode (UTF-8, with BOM) which includes a byte-order mark; Unix tools don't react well to such things. Saving it as Unicode (UTF-8) will save the file without a BOM, and this will probably solve the problem.

R.

Paul Gobble

unread,
Mar 6, 2020, 2:31:38 PM3/6/20
to BBEdit Talk
Sam, I'll buy you a beer next time I see ya. You figured it out.  I resaved as UTF-8 no BOM and it works!  Thank you.

Sam Hathaway

unread,
Mar 12, 2020, 11:19:10 AM3/12/20
to BBEdit Talk

Glad I could help, Paul. I like sour beers and belgians. ;-)

To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/67f2ab19-de18-48b9-9c88-13ad9d1a7eae%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages