MacOS Problem: "bad interpreter: /usr/local/opt/python@2/bin/python2.7: no such file or directory"

Hello!
I am using PlatformIO in VSCode on MacOS 10.15.7
I have had an issue with an outdated openocd version which was fixed in this thread. There it was also discovered that I’m getting an error regarding the python version. The full error is: zsh: /Users/username/Library/Python/2.7/bin/pio: bad interpreter: /usr/local/opt/python@2/bin/python2.7: no such file or directory, but apart from this error everything worked just fine.
Now Platformio notified me that it was updated and asked me to reload the IDE, which I did and felt it was a good idea to check my version, since in the thread linked above i had switched to the dev version, and I’d like to switch back to release once that update was live.

Turns out when I try to run pio --version I get the python error like before, but followed by PlatformIO, version 5.0.2

So I’d like fix the python error but I have no clue where to start. I have just recently done a python cleanup where I removed every python version except the one that ships with mac os (2.7), and then installed python3 using homebrew.

Some more info:
Opening a platformio terminal from the toolbar, then typing python --version results in Python 2.7.16

which -a python python3 results in:

/usr/bin/python
/usr/local/bin/python3
/usr/bin/python3

brew list python returns a bunch of: /usr/local/Cellar/python@3.8/... but nothing else, just as expected

User Builtin Python and Use Builtin PIOCore are checked in the settings.

~/.platformio/python3 exists and calling --version on the binary returns Python 3.8.4.

In general it seems that everything works just fine, I just get this weird error about python 2.7.16 …

Seems like you have globally installed PlatformIO with your Python 2.7 pip installation? I would recommend to pip uninstall platformio and then pip3 install platformio with the Python3 version of pip.

1 Like
  1. pip uninstall platformio
  2. Remove ~/.platformio/penv folder and restart VSCode.
  3. Open PlatformIO CLI in VSCode and type
pio system info

Share here.

@maxgerhardt I do not have a global pio install. I only have it installed as vscode extension. running pip uninstall platformio confirms: WARNING: Skipping platformio as it is not installed.
Since I also do not intend installing it globally I have skipped the pip3 install platformio suggestion. Kindly let me know if you still want me to try this, does not seem obvious though.

@ivankravets

zsh: /Users/wolfgang/Library/Python/2.7/bin/pio: bad interpreter: /usr/local/opt/python@2/bin/python2.7: no such file or directory
--------------------------  -------------------------------------------------
PlatformIO Core             5.0.2
Python                      3.8.4-final.0
System Type                 darwin_x86_64
Platform                    macOS-10.15.7
File System Encoding        utf-8
Locale Encoding             UTF-8
PlatformIO Core Directory   /Users/wolfgang/.platformio
PlatformIO Core Executable  /Users/wolfgang/Library/Python/2.7/bin/platformio
Python Executable           /Users/wolfgang/.platformio/penv/bin/python
Global Libraries            0
Development Platforms       9
Tools & Toolchains          32
--------------------------  -------------------------------------------------

And because I’m sure the qustion will arise:
Bildschirmfoto 2020-10-27 um 11.33.36
yes use builtin core and python is checked in the settings :slight_smile: I have no clue why it would not use the builtin core executable …

The pio executables in ~/Library/Python/2.7/bin are from october 2019 :hushed: I have no clue how they got there and why they are even relevant in this case …

I have deleted all pio related files from that folder and now it all seems in order.

--------------------------  -----------------------------------------------
PlatformIO Core             5.0.2
Python                      3.8.4-final.0
System Type                 darwin_x86_64
Platform                    macOS-10.15.7
File System Encoding        utf-8
Locale Encoding             UTF-8
PlatformIO Core Directory   /Users/wolfgang/.platformio
PlatformIO Core Executable  /Users/wolfgang/.platformio/penv/bin/platformio
Python Executable           /Users/wolfgang/.platformio/penv/bin/python
Global Libraries            0
Development Platforms       9
Tools & Toolchains          32
--------------------------  -----------------------------------------------

however, opening a pio-terminal in vscode and typing python --version still dumps 2.7.16. No more errrors though.

This is normal, please don’t panic. This is a default macOS Python 2. I have it too :slight_smile:
There are macOS services that depend on it. It is visible globally in a system.

Your configuration looks good for me.

Yeah I’m aware of the apple version and it’s purpose, no panic, no worries :slight_smile:
I had the impression – also from your previous troubleshooting suggestions in the thread above – that when running the command from the pio-terminal in vscode it should actually run the pio-internal version and thus return 3.8 and was thus related to the problem.
But if it’s not then everything is fine :slight_smile: